1.

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

Answer»

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"));


Discussion

No Comment Found