我有桌子的按钮。每行表格由3个按钮组成。我必须点击其中的一个3,然后转到其他页面查看更改。在我断言改变是好的之后,我想回到那些按钮并将它们设置为初始状态。所以在列表中我存储了这些按钮的初始状态。但是当我转到其他页面查看更改并返回时将这些按钮设置为初始状态。我得到StaleElementReferenceException。我明白为什么,但即使如果我再次初始化元素我得到同样的错误。我使用页面对象模式,并以这种方式初始化元素PageFactory.initElements(new ElementDecorator(Driver.getInstance()), this);
即使我把Thread.sleep,然后初始化元素钢我得到的错误。Selenium StaleElementReferenceException。如何绕过它
-1
A
回答
0
不要使用thread.sleep,使用下面的方法返回布尔元素,当元素被找到时为true,当元素由于某种原因丢失时(或者你的xpath可能不够好),返回false。超时是等待多久才可以说,该元素是不存在(即5将等待5秒钟,然后扔找不到元素除外)
public boolean waitForElement(String elementXpath, int timeOut) {
try{
WebDriverWait wait = new WebDriverWait(driver, timeOut);
boolean elementPresent=wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(elementXpath)).isDisplayed());
System.out.printf("%nElement is present [T/F]..? ")+elementPresent;
}
catch(TimeoutException e1){e1.printStackTrace();elementPresent=false;}
return elementPresent;
}
还当你回到你的表的另一项建议能是之前试图找到任何元素刷新页面:
driver.navigate().refresh();
相关问题
- 1. StaleElementReferenceException selenium webdriver python
- 2. 如何在Selenium中处理这个StaleElementReferenceException?
- 3. 如何避免Selenium中的“StaleElementReferenceException”?
- 4. Selenium WebDriver - 处理StaleElementReferenceException(Python)
- 5. 使用EventFiringWebDriver时Selenium StaleElementReferenceException
- 6. Selenium WebDriver中的StaleElementReferenceException java测试
- 7. ajax选项上的Selenium StaleElementReferenceException选项
- 8. Python Selenium WebDriverWait和Click不一致给StaleElementReferenceException()
- 9. StaleElementReferenceException在Selenium中导航时WebDriver
- 10. 如何处理StaleElementReferenceException
- 11. InternetExplorerDriver StaleElementReferenceException
- 12. 硒StaleElementReferenceException
- 13. 如何编程Selenium以绕过登录页面?
- 14. 硒的Python StaleElementReferenceException
- 15. 如何绕过IndexError
- 16. C#:如何绕过
- 17. 如何绕过default_scope?
- 18. 如何绕过AppWidgetManager.ACTION_APPWIDGET_PICK?
- 19. Scrapy和硒StaleElementReferenceException
- 20. 硒:StaleElementReferenceException
- 21. geb StaleElementReferenceException
- 22. 如何解决'Selenium StaleElementReferenceException,该元素似乎与DOM断开连接。 “?
- 23. 如何绕过Time.time刻度
- 24. 如何绕过Microsoft.Bcl.Build警告
- 25. 如何绕过@JsonIgnore注释?
- 26. 如何绕过页面
- 27. 如何绕过yii验证?
- 28. 如何绕过j2me标志
- 29. 如何绕过Jenkins镜像
- 30. 如何绕过完成
的可能的复制[?如何避免“StaleElementReferenceException”中硒(http://stackoverflow.com/questions/12967541/how-to-avoid -staleelementreferenceexception-in-selenium) – JeffC
请阅读[问]和[预计需要多少研究工作?](https://meta.stackoverflow.com/questions/2 61592 /堆栈溢出 - 用户期望的研究工作量)请提供您尝试过的代码和执行结果,包括任何错误消息等。还要提供页面链接和/或相关的HTML。 – JeffC