我有桌子的按鈕。每行表格由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 WebDriver - 處理StaleElementReferenceException(Python)
- 4. 使用EventFiringWebDriver時Selenium StaleElementReferenceException
- 5. ajax選項上的Selenium StaleElementReferenceException選項
- 6. Selenium WebDriver中的StaleElementReferenceException java測試
- 7. 如何處理StaleElementReferenceException
- 8. 硒StaleElementReferenceException
- 9. 硒的Python StaleElementReferenceException
- 10. C#:如何繞過
- 11. 如何繞過default_scope?
- 12. 如何繞過AppWidgetManager.ACTION_APPWIDGET_PICK?
- 13. Scrapy和硒StaleElementReferenceException
- 14. 硒:StaleElementReferenceException
- 15. 如何解決'Selenium StaleElementReferenceException,該元素似乎與DOM斷開連接。 「?
- 16. 如何繞過繼承
- 17. 如何繞過插座?
- 18. 如何繞過Jenkins鏡像
- 19. 如何繞過yii驗證?
- 20. 如何繞過完成
- 21. 如何繞過htaccess規則?
- 22. 如何繞過頁面
- 23. 使用Selenium進行Web抓取:隨機拋出的代碼StaleElementReferenceException
- 24. 遍歷頁面並在Python中獲取StaleElementReferenceException Selenium
- 25. 使用selenium和python迭代結果頁面:StaleElementReferenceException
- 26. Selenium 2 StaleElementReferenceException當使用DropDownList與AutoPostBack與InternetExplorerDriver
- 27. 如何繞過或使用Java在selenium webdriver中處理Windows身份驗證
- 28. StaleElementReferenceException雖然試圖move_to_element(Python)
- 29. 繞過硒在capcha
- 30. Maven/Java Crawler - StaleElementReferenceException
的可能的複製[?如何避免「StaleElementReferenceException」中硒(http://stackoverflow.com/questions/12967541/how-to-avoid -staleelementreferenceexception-in-selenium) – JeffC
請閱讀[問]和[預計需要多少研究工作?](https://meta.stackoverflow.com/questions/2 61592 /堆棧溢出 - 用戶期望的研究工作量)請提供您嘗試過的代碼和執行結果,包括任何錯誤消息等。還要提供頁面鏈接和/或相關的HTML。 – JeffC