Selenium waiting for the entire page to load.

17,190 views
Skip to first unread message

Deepak

unread,
May 31, 2012, 9:48:44 AM5/31/12
to webdriver
My web page has a lot of java script to load, so the page load will
take a lot of time. The elements I want are loaded before all the page
is loaded. I just want my script to continue when the elements are
loaded without waiting for the entire page to load.

I have implemented the Implicit and Explicit timeouts, but further
noticed that they effect after the entire page is loaded.
Also I tried with pageLoadTimeout and setScriptTimeout() ,not
successful.

for example a login screen:

final String loginURL = Test.url+"/login.htm";
/* The page Load Timeout() is making the
selenium to timout after 30 seconds without checking the element.It is
just checking whether the page is loaded in 30 seconds, if it is not ,
throws timeout exception.

//driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);

/*The setScriptTimeout() is not doing
anything in affect.
//driver.manage().timeouts().setScriptTimeout(15,
TimeUnit.SECONDS);

driver.get(loginURL);

/* Explicit timeout to wait for the Login
button , this effect after the page is loaded*/
WebElement LoginButton = driver.findElement(By.name("commit"));
if( LoginButton.equals(null))
System.out.println("Cant find Login Button");

Wait<WebDriver> wait = new WebDriverWait(driver, 10);
// Wait for search to complete
wait.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver webDriver) {
System.out.println("Searching...");
return webDriver.findElement(By.name("commit")) !=
null;
}
});

System.out.println("Element found"+LoginButton.getTagName());

driver.findElement(By.id("loginId")).sendKeys(userName);
driver.findElement(By.id("loginPwd")).sendKeys(password);
driver.findElement(By.name("commit")).click();


FYI. I am using seleniumWebDriver2.21.0, Firefox 12.0. Is there any
method I can follow to not wait for the entire page to load?

Mike Riley

unread,
May 31, 2012, 12:05:59 PM5/31/12
to webd...@googlegroups.com
First off, FF 12 is not supported by 2.21.0, so you should upgrade to 2.22.0 which does support FF 12.

I have not used the implicit or explicit timeouts myself, so I can't comment as to that, but see if the upgrade to a version that supports the Firefox you are testing with solves the problem.

Mike

Deepak

unread,
Jun 1, 2012, 12:15:23 AM6/1/12
to webd...@googlegroups.com
Upgrade to selenium2.22.0 also not helping..
The problem here is :
driver.get(loginURL) <--  This call taking long enough time to load all the entire page. My elements loginID,loginPWD and Commit are loaded way before the entire page is loaded. Is there a way I can stop the page to load once my elements (loginID, loginPWD,Commit) are loaded?


mukesh rawat

unread,
Jun 1, 2012, 2:56:00 AM6/1/12
to webd...@googlegroups.com
Hi Deepak,
You can use presenceOfElementLocated(By locator) or visibilityOfElementLocated(By locator) .

methods of class ExpectedConditions.



Thanks,
Mukesh

Mark Collin

unread,
Jun 1, 2012, 4:03:31 AM6/1/12
to webd...@googlegroups.com

It sounds like the problem here is that the page has so much JavaScript it is unusable.

 

Why not raise that as a bug and try and get your devs to reduce the level of JavaScript required?

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/ayVfjQdvO3wJ.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.

darrell

unread,
Jun 1, 2012, 9:29:36 AM6/1/12
to webdriver
Have a look at https://addons.mozilla.org/en-US/firefox/addon/lori-life-of-request-info/.
This plugin will tell you time to first byte, total load time and
number of bytes loaded. If the time to load the page is more than 3
seconds I'd consider it a bug. The 3 second criteria is actually old.
Studies from 10 to 20 years ago showed that users will not wait longer
than 3 seconds for something to happen. If a page load is taking
longer than 3 seconds there is a serious problem. My personal
experience is that most people will wait 1 to 1.5 seconds.

If the page load is taking too long, development needs to look at ways
of improving this. It could be as simple as improving network
performance, caching, removing formatting from javascript files (e.g.
jquery.min.js rather than jquery.js) or it could be a design change.

Darrell

Deepak

unread,
Jun 1, 2012, 11:03:23 AM6/1/12
to webd...@googlegroups.com
Thank you all, for your suggestions.
I ll get to the dev team.

Aparna

unread,
Jul 11, 2012, 1:51:07 AM7/11/12
to webd...@googlegroups.com
Even we agree with all Web application performance, the main problem is not solved here.

Deepak - When you use PageTimeOut, do you get exception or page takes more than 30 seconds to load?

This will help finding out if the problem is with 'PageTimeOut' command or the way it is being used in script.

In my experience, I get a exception if I use very small PageTimeOut like 2 seconds.

It might be that all the JavaScript you are referring are loaded as part of 'Onload' event.

Roosevelt P

unread,
Jan 19, 2014, 6:01:09 PM1/19/14
to webd...@googlegroups.com, ramakris...@gmail.com
Hi Agree with Aparna! The main bug is still not fixed and should be addressed for optimal selenium success.

I am having the exact issue Deepak is having. The quick fix works fine on a development environment but if you run the tests on a staging environment with tight security before pushing out the final release, the tests will fail.

I created a bug report about it here: http://code.google.com/p/selenium/issues/detail?id=6867&sort=-id&colspec=ID%20Stars%20Type%20Status%20Priority%20Milestone%20Owner%20Summary

Seems like a lot of of you are dealing with this issue and your vote (a start) could get the bug report noticed.
Reply all
Reply to author
Forward
0 new messages