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,090 points
5,810 views

2 answers 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,710 points
0 votes

use 

(JavascriptExecutor) driver).executeScript("return document.readyState").toString().equals("complete");

answered Sep 3 by Sri
• 2,970 points

Related Questions In Selenium

+1 vote
0 answers

python selenium error: element is not attached to the page document

I am scraping Banggood, the problem is ...READ MORE

Apr 9 in Selenium by eslam
• 130 points
3,009 views
0 votes
2 answers

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

WebDriver driver; JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("document.getElementById('id123').setAttribute('attr', ...READ MORE

answered Sep 3 in Selenium by Sri
• 2,970 points
16,276 views
+1 vote
4 answers

Need to wait until page is completely loaded - Selenium WebDriver

You can try something like -  new WebDriverWait(firefoxDriver, ...READ MORE

answered Dec 20, 2019 in Selenium by Robin
29,554 views
0 votes
2 answers

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,520 points
3,997 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,710 points
1,840 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31 in Selenium by Sri
• 2,970 points
4,949 views
0 votes
1 answer
0 votes
2 answers

C# and Selenium: Wait Until Element is Present

WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0,0,5)) ...READ MORE

answered Sep 3 in Selenium by Sri
• 2,970 points
9,678 views