Explore Courses Blog Tutorials Interview Questions
+2 votes
in DevOps and Agile by (19.4k points)

Can anyone let me how can I make selenium wait until the time the page loads completely? I want something generic, I know I can configure WebDriverWait and call something like 'find' to make it wait but I don't go that far. I just need to test that the page loads successfully and move on to next page to test.

I found something in .net but couldn't make it work in java ...

IWait<IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(30.00));

wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));

Any thoughts anyone?

1 Answer

+1 vote
by (27.5k points)
edited by

The following command will wait up to 10 seconds for page loading. If the page loading exceeds that time it will throw the TimeoutException.

driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);

For more information please go through the following tutorial to get more info about selenium:

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s Selenium training and certification!

Browse Categories