0

Before input the value we are using wait method until DOM load,if i used webdriver wait im getting stale element error message ,what is the best approach to use wait method where we require page to load DOM elements

public static void waitForPageToComplete(WebDriver driver) {
    ExpectedCondition<Boolean> pageLoad = new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver driver) {
            return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete");
        }
    };
    try {
        Thread.sleep(5000);
        WebDriverWait wait = new WebDriverWait(driver, ofSeconds(2));
        wait.until(pageLoad);
    } catch (Exception e) {
        System.out.println("Wait for page to load" + e);
    }
}
sarath k
  • 3
  • 2
  • I don't know about how it is on java, but checking `document.readyState` in selenium python often doesn't work. – Reyot Jul 15 '23 at 10:42

0 Answers0