Selenium wait until document is ready

71 views
Skip to first unread message

honey asin

unread,
Jan 7, 2018, 9:53:04 PM1/7/18
to Selenium Users
Hi,

 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"));

Thank You
Honey Asin

Krishnan Mahadevan

unread,
Jan 7, 2018, 9:58:32 PM1/7/18
to seleniu...@googlegroups.com

AFAIK page loads in selenium are all blocking calls which internally wait till the page is loaded before it moves on to executing the next statement.

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/8c44298d-90ac-4bae-a49c-d0152649e930%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

venkatesh aarelly

unread,
Jan 11, 2018, 5:22:33 AM1/11/18
to Selenium Users
Hi Honey Asin,

Here is the code for selenium wait until the time the page loads completely.
Wait<WebDriver> wait = new WebDriverWait(this.driver, 30);
            wait.until(new Function<WebDriver, Boolean>() {
                public Boolean apply(WebDriver driver) {
                   
                    return String
                            .valueOf(((JavascriptExecutor) driver).executeScript("return document.readyState"))
                            .equals("complete");
                }
            });

Use make this method as generic ans use whereever you want.
Reply all
Reply to author
Forward
0 new messages