0
一个接一个我使脚本搜索我intersted字符串集,但我有错误。 我如何解决以下问题:点击链接与硒的webdriver Python
links = driver.find_elements_by_xpath("xpath")
for x in range(0, len(links)):
driver.implicitly_wait(2)
links[x].click()
try:
driver.implicitly_wait(3)
DO something
driver.back()
print("Mission completed!!")
except (ElementNotVisibleException, NoSuchElementException):
driver.back()
print("No action")
Error:
selenium.common.exceptions.StaleElementReferenceException: Message: The element reference is stale. Either the element is no longer attached to the DOM or the page has been refreshed.
in line: links[x].click()
THX人从每一页!你教了我很多很好的代码:)这是做这件事的最佳范例吗?用20个链接搜索后,我的网站看起来像谷歌一样。 – PythonLearn
如果只有一个包含20个链接的页面,您可以按原样使用它,但是如果您有分页(每个页面包含20个链接),则可以执行另一个循环,单击“Next”按钮在每个页面附加链接然后通过提供的循环。一个循环 - 收集链接,一个 - 遵循引用列表中的链接 – Andersson