Do we have any generic function to check if page has completely loaded in Selenium

前端 未结 5 1339
清歌不尽
清歌不尽 2020-11-21 22:56

I am trying to check if web page is loaded completed or not (i.e. checking that all the control is loaded) in selenium.

I tried below code:

new WebDr         


        
5条回答
  •  春和景丽
    2020-11-21 23:44

        public static void waitForPageToLoad(long timeOutInSeconds) {
        ExpectedCondition expectation = new ExpectedCondition() {
            public Boolean apply(WebDriver driver) {
                return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete");
            }
        };
        try {
            System.out.println("Waiting for page to load...");
            WebDriverWait wait = new WebDriverWait(Driver.getDriver(), timeOutInSeconds);
            wait.until(expectation);
        } catch (Throwable error) {
            System.out.println(
                    "Timeout waiting for Page Load Request to complete after " + timeOutInSeconds + " seconds");
        }
    }
    

    Try this method

提交回复
热议问题