【发布时间】:2015-01-16 04:17:45
【问题描述】:
在 python 中使用 Selenium 时出现以下错误:
selenium.common.exceptions.StaleElementReferenceException: Message: u'stale element reference: element is not attached to the page document\n
有趣的是,错误在 for 循环中的不同时间弹出。有时它会通过例如。 4次迭代和其他时间,例如。 7.
一些正在运行的相关代码是:
for i in range(0, 22):
u = driver.find_elements_by_id("data")
text = u[0].get_attribute("innerHTML")
driver.find_elements_by_class_name("aclassname")[0].click()
这个错误是什么意思,我可以尝试解决什么问题?
【问题讨论】:
-
这个错误或多或少意味着“我找不到元素”。解决这个问题的方法是以某种方式减慢它的速度。可能通过隐式或显式等待。
-
好的。什么是隐式等待?
-
或者,更好的是,我将如何显式等待直到
aclassname元素被加载? -
@SiKing no answers 解决了这个问题。因为我们在 2-3 次迭代后得到 StaleElementReferenceException。你能给我确切的解决方案吗
标签: python html selenium-webdriver dom