简体   繁体   中英

wait until page loads completely using selenium 3?

public boolean WaitForPageToLoad(){   

final ExpectedCondition<Boolean> pageLoadCondition = new ExpectedCondition<Boolean>() {
        public Boolean apply(final WebDriver driver) {
            return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete");
        }
    };

    final WebDriverWait wait = new WebDriverWait(this.driver, this.defaultTimeoutinSeconds);
    final boolean IsPageLoad = wait.until(pageLoadCondition);

    if (!IsPageLoad) {
        log.logInfo("Page doesn't load after " + this.defaultTimeoutinSeconds + " seconds");
    }
    return IsPageLoad;
}

above code was working in selenium 2.53.1 but when I upgraded to Selenium 3.1.X, above code is not compatible. Plaese anyone convert above code to make it compatible with selenium 3. I am getting below error
The method until(Function) in the type FluentWait is not applicable for the arguments (new ExpectedCondition(){})

This code works for me for Selenium3

driver = (new Driver(Driver.Browser.SAFARI)).getDriver();

driver.navigate().to("http://www.epochconverter.com/");

waitForLoad(driver);

static void  waitForLoad(WebDriver driver) {
    new WebDriverWait(driver, 50).until((ExpectedCondition<Boolean>) wd ->
    ((JavascriptExecutor) wd).executeScript("return document.readyState").equals("complete"));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM