错误说明了一切:
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 与特定 页码 (例如 3 , 4 , 5 ,等)是 可点击 如下:
WebDriverWait(self.driver, 30).until(EC.element_to_be_clickable((By.XPATH, "//a[contains(text(),'3')]"))).click()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)