Peter Jonsson

Snippet: Wait for document ready with Selenium

10. Apr. 2020

void waitForDocumentReady(WebDriver driver, Duration timeout) {
    Wait<WebDriver> wait = new WebDriverWait(driver, timeout);
    JavascriptExecutor js = ((JavascriptExecutor) driver);
    String getState = "return document.readyState;";
    wait.until(_ -> js.executeScript(getState).equals("complete"));
}