Wait for page load in Selenium

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

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

30条回答
  •  感情败类
    2020-11-22 08:09

    Here is a Java 8 version of the currently most upvoted answer:

    WebDriverWait wait = new WebDriverWait(myDriver, 15);
    wait.until(webDriver -> ((JavascriptExecutor) myDriver).executeScript("return document.readyState").toString().equals("complete"));
    

    Where myDriver is a WebDriver object (declared earlier).

    Note: Be aware that this method (document.readyState) only checks the DOM.

提交回复
热议问题