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);
}
}