Make Selenium Webdriver Stop Loading the page if the desired element is already loaded?

0
0

I am creating a test and having some issues. Here is the scenario. I use Selenium Web driver to fill out a form on Page1 and submit the form by clicking a button. Page2 starts loading… but the problem is, Page2 uses Google Analytics codes, and sometimes it takes forever for the page to stop loading.

Even though the expected element is already present, Selenium web driver does not proceed until the whole web page is fully loaded.

How do I make Selenium to move on to the next task or stop loading external javascript/css if the expected element is already present?

I tried tweaking the following settings but no luck.

driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
driver
.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
driver
.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

TEMPORARY SOLUTION: Scroll below for answer!

  • You must to post comments
0
0

So, I reported to Selenium about these issues. And the temporary workaround is… messing with Firefox’s timeout settings. Basically by default Firefox waits about 250 seconds for each connection before timing you out. You can check about:config for the details. Basically I cranked it down so Firefox doesn’t wait too long and Selenium can continue as if the page has already finished loading :P.

Similar config might exist for other browsers. I still think Selenium should let us handle the pagetimeout exception. Make sure you add a star to the bug here: http://code.google.com/p/selenium/issues/detail?id=6867&sort=-id&colspec=ID%20Stars%20Type%20Status%20Priority%20Milestone%20Owner%20Summary, so selenium fixes these issues.

FirefoxBinary firefox = new FirefoxBinary(new File("/path/to/firefox.exe"));
FirefoxProfile customProfile = new FirefoxProfile();
customProfile
.setAcceptUntrustedCertificates(true);
customProfile
.setPreference("network.http.connection-timeout", 10);
customProfile
.setPreference("network.http.connection-retry-timeout", 10);
driver
= new FirefoxDriver(firefox, customProfile);
driver
.manage().deleteAllCookies();
  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website