python爬虫程序,用Selenium模拟点击时报出异常NoSuchElementException:Unable to locate......
出错原因:https://www.cnblogs.com/cttcarrotsgarden/p/11210883.html
异常通常发生于找不到目标元素的时候
导入Selenium的NoSuchElementException包
from selenium.common.exceptions import NoSuchElementException
try:
xpath = ".//table//tr[1]//td[1]"
browser.find_element_by_xpath(xpath).click()
except NoSuchElementException:
print("没有找到元素!")