Need Selenium to wait until the document is ready.

0 votes

Does anyone know how to make selenium wait until the page loads completely? I want something simple which can be used else where also because I'm not a very technical person and I have like 1000 pages to test. So probably need to wait for sometime and move to test the next page.

So I got something in .net. But I want something similar for 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?

Apr 20, 2018 in Selenium by kappa3010
• 2,020 points
1,838 views

1 answer to this question.

0 votes

Use this:

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

This piece of code will make your WebDriver wait up to 10 seconds for all elements in the page to load completely. If beyond this time the element is not found, then an exception called 'TimeoutException' will be thrown. 

This technique is called an implicit wait.

answered Apr 20, 2018 by king_kenny
• 3,610 points

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer

Is it possible to manually set the attribute value of a Web Element using Selenium?

Yes, its very much possible. You just ...READ MORE

answered May 8, 2018 in Selenium by king_kenny
• 3,610 points
5,088 views
0 votes
1 answer

I need to release the memeory allocated to Selenium chromedriver.exe while for tests

The usage of the commands is incorrect. driver.close() ...READ MORE

answered May 21, 2018 in Selenium by sniffy_god
• 760 points
604 views
0 votes
1 answer

To check that the web page is loaded or not using Selenium Web Driver?

The solution is using Implicit Wait which ...READ MORE

answered May 24, 2018 in Selenium by Meci Matt
• 9,420 points
4,410 views
0 votes
1 answer

Need to wait until page is completely loaded - Selenium WebDriver

Using Thread.Sleep(); is one approach; but its ...READ MORE

answered Apr 2, 2018 in Selenium by nsv999
• 5,070 points
4,298 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,070 points
441 views
0 votes
1 answer

Impilicit wait vs Explicit wait vs Fluent wait

Implicit wait: Your telling the WebDriver the ...READ MORE

answered Apr 13, 2018 in Selenium by king_kenny
• 3,610 points
708 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

C# and Selenium: Wait Until Element is Present

Your logic is just slightly off..The actual ...READ MORE

answered Apr 20, 2018 in Selenium by king_kenny
• 3,610 points
4,239 views