Selenium单击一次,但下一步单击将返回StaleElementReferenceException

Selenium单击一次,但下一步单击将返回StaleElementReferenceException,第1张

Selenium单击一次,但下一步单击将返回StaleElementReferenceException

错误说明了一切:

selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document

for()
循环内的程序中,您将在页面上找到
<a>
文本标记为 > >*的tag元素并进行调用,
click()
并且由于 HTML DOM
发生更改而导致的
click()
事件。当您的程序第二次迭代循环时,也许未加载标识为的 WebElement ,但是 Selenium
尝试引用以前已经 过时的 迭代中的搜索。因此,您会看到 StaleElementReferenceException
for()


driver.find_element_by_xpath("//a[contains(text(),'>>')]")
__

***

一种令人信服的迭代页面的方法是:

driver.find_element_by_xpath("//a[contains(text(),'>>')]").click()

可以诱导WebDriverWait在-结合expected_conditions子句设置为element_to_be_clickable为
WebElement 与特定 页码 (例如 345 ,等)是 可点击 如下:

WebDriverWait(self.driver, 30).until(EC.element_to_be_clickable((By.XPATH, "//a[contains(text(),'3')]"))).click()


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5666350.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存