对于 DOM
<div class="col-md-6">
<div class="refreshIcon refreshFiling">
<a href="javascript:;" onclick="CFRefresh('CFanncEquity')"><img src="/assets/images/refresh-icon.svg" alt="Refresh" title="Refresh">Refresh</a>
</div>
</div>
用我的Python selenium 代码
refresh_button = driver.find_element(By.XPATH, '//div[@class="refreshIcon"]/a')
我得到了
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//div[@class="refreshIcon"]/a"}
(Session info: chrome=126.0.6478.126); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception
为什么?
根据你给的DOM,xpath应该是:
//div[contains(@class, "refreshIcon")]/a
或
//div[@class="refreshIcon refreshFiling"]/a