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 21, 2018 in Selenium by kappa3010
• 2,090 points
11,754 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 21, 2018 by king_kenny
• 3,710 points
0 votes

use 

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

answered Sep 4, 2020 by Sri
• 3,190 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 10, 2020 in Selenium by eslam
• 130 points
10,059 views
+1 vote
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 4, 2020 in Selenium by Sri
• 3,190 points
27,533 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 21, 2019 in Selenium by Robin
64,347 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,500 points
13,762 views
0 votes
1 answer

Impilicit wait vs Explicit wait vs Fluent wait

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

answered Apr 14, 2018 in Selenium by king_kenny
• 3,710 points
4,346 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

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

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,184 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 4, 2020 in Selenium by Sri
• 3,190 points
11,969 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP