0 votes
in Selenium by
In Selenium, how will you wait until a web page has been loaded completely?

1 Answer

0 votes
by
There are two methods of making sure that the web page has been loaded completely in Selenium.

They are as follows:

1. Immediately after creating the webdriver instance, set an implicit wait:

temp = driver.Manage().Timeouts().ImplicitWait;

On every page navigation or reload, this will try to wait until the page is fully loaded.

2. Call JavaScript return document.readyState till "complete" is returned after page navigation. As a JavaScript executor, the web driver instance can be used.

Code example:

new WebDriverWait(firefoxDriver, pageLoadTimeout).until(

     webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));
...