How to avoid “StaleElementReferenceException” in Selenium?

前端 未结 16 2274
一向
一向 2020-11-22 12:12

I\'m implementing a lot of Selenium tests using Java. Sometimes, my tests fail due to a StaleElementReferenceException. Could you suggest some approaches to mak

16条回答
  •  时光取名叫无心
    2020-11-22 12:38

    Maybe it was added more recently, but other answers fail to mention Selenium's implicit wait feature, which does all the above for you, and is built into Selenium.

    driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);

    This will retry findElement() calls until the element has been found, or for 10 seconds.

    Source - http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp

提交回复
热议问题