HomeSelenium

Selenium Interview Question – How will you ensure page has been loaded completely?

Selenium Interview Question – How will you ensure page has been loaded completely?

Hi all,

The following is the Selenium Interview question along with its answer. If you are interested in finding out our complete list of Selenium Interview questions, you can refer to http://www.qafox.com/selenium-interview-questions/


Question: How will you ensure page has been loaded completely?


While automating any application using Selenium Web Driver, we may come across some situations where we have to wait for the page to load completely, before performing any actions on any elements on the page. In order to understand how to wait for the complete page to load before performing any activities, go through the below explanation:

We can execute the JavaScript code having document.readyState parameter to check whether the ‘complete’ status of the page is returned or not.

Example for using the above specified JavaScript code in Selenium for ensuring the completeness of page loading: The below reusable user defined method can be called anytime you want to check the completeness of page loading:


public void waitForPageLoad(WebDriver driver, int timeout) {

ExpectedCondition<Boolean> pageLoadCondition = new ExpectedCondition<Boolean>() {

public Boolean apply(WebDriver driver) {

return ((JavascriptExecutor)driver).executeScript(“return document.readyState”).equals(“complete”)}

};

WebDriverWait wait = new WebDriverWait(driver, timeout);

wait.until(pageLoadCondition);

}


We can call the above method using the following method calling statement:

waitForPageLoad(driver, 30); //waits till page load gets completed by setting a time limit of 30 seconds


If you are interested in finding out our complete list of Selenium Interview questions, you can refer to http://www.qafox.com/selenium-interview-questions/


Please leave your questions/comments/feedback below.

Happy Learning ?

Naveen Repala (www.QAFox.com)

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *

For FREE Testing Tutorials & Videos

X
Open chat
Contact Us on Whatsapp