Wait for page load in Selenium

后端 未结 30 2758
攒了一身酷
攒了一身酷 2020-11-22 07:12

How do you make Selenium 2.0 wait for the page to load?

30条回答
  •  孤城傲影
    2020-11-22 08:12

    You may remove the System.out line. It is added for debug purposes.

    WebDriver driver_;
    
    public void waitForPageLoad() {
    
        Wait wait = new WebDriverWait(driver_, 30);
        wait.until(new Function() {
            public Boolean apply(WebDriver driver) {
                System.out.println("Current Window State       : "
                    + String.valueOf(((JavascriptExecutor) driver).executeScript("return document.readyState")));
                return String
                    .valueOf(((JavascriptExecutor) driver).executeScript("return document.readyState"))
                    .equals("complete");
            }
        });
    }
    

提交回复
热议问题