10

sometimes in my test done with Selenium 2.41 and tested with Firefox 28 the execution hangs waiting for page to load.

This is the wait condition:

int time = 30;    
WebDriverWait wait = new WebDriverWait(webDriver, time);
ExpectedCondition<Boolean> pageLoadCondition = new ExpectedCondition<Boolean>() {
   public Boolean apply(WebDriver driver) {
      return ((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete");
    }
};
wait.until(pageLoadCondition);

It's supposed that after 30 seconds this method will throw a TimeoutException, but it's not, sometimes hangs forever. This is the stacktrace produced in these situations:

java.lang.Thread.State: RUNNABLE at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(Unknown Source) at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:160) at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:84) at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:273) at org.apache.http.impl.conn.LoggingSessionInputBuffer.readLine(LoggingSessionInputBuffer.java:116) at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:140) at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57) at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:260) at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:283) at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:251) at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:223) at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:271) at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123) at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:682) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:486) at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57) at org.openqa.selenium.remote.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:322) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:301) at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:165) at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute(FirefoxDriver.java:362) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:568) at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:504) at es.tao.commonservices.selenium.tests.TAORobotWebDriver$1.apply(TAORobotWebDriver.java:6227) at es.tao.commonservices.selenium.tests.TAORobotWebDriver$1.apply(TAORobotWebDriver.java:1) at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208) at es.tao.commonservices.selenium.tests.TAORobotWebDriver.waitToLoad(TAORobotWebDriver.java:6230) at es.tao.commonservices.selenium.tests.TAORobotWebDriver.handleWaitToLoad(TAORobotWebDriver.java:6110)

I have set this preference for firefox profile, but it's still not working:

ffProfile = new FirefoxProfile();
ffProfile.setPreference("webdriver.load.strategy", "unstable");

Also have this properties set:

webDriver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
webDriver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
vbail
  • 364
  • 3
  • 14
  • Would you be open to a solution that uses a normal driver.get(url) but then uses a FLuentWait untill an expected element is loaded? – HRVHackers Apr 19 '14 at 16:56
  • Hi gorbysbm, I'm developing a kind of robot that tests the application. Sometimes I don't have "the" element to wait for, so I have to wait until the document is ready. Anyway, waiting for an element to appear this error would happen because I have tried it. Thanks! – vbail Apr 23 '14 at 08:52
  • Just a theory, but wouldn't using FluentWait to wait for the "body" element of the page to load accomplish the same thing? I don't see fluentWait in your code it should look like this: http://stackoverflow.com/questions/12041013/selenium-webdriver-fluent-wait-works-as-expected-but-implicit-wait-does-not . Why don't you try getting rid of that Javascript code and see if fluentWait will work – HRVHackers Apr 23 '14 at 16:21
  • I have the same problem with Selenium 2.42 and Firefox 28. Firefox status bar will say "Transferring data from XXX..." forever, and never returns control to Selenium. In the console, the document.readyState stays stuck on "loading". – Yoshi May 28 '14 at 00:15
  • i faced similar issue and resolved it by changing the wait method. But in my case the same java script wait has been used at too many places so replacing that was a big risk for me. So I changed java script wait method at only those place where code was actually hanging. – Priyanshu Sep 18 '14 at 10:02

2 Answers2

1

You may want to try Firefox 27.01. I upgraded to Firefox 28.0 and it seemed to break some tests I was doing using watir-webdriver. I went back to 27.01 and the tests ran again(if you go back download the whole install package as the setup only, does not seem to let you turn off auto-update so it updates itself to 28.0).

The fails were using hover and find_element.

coolercargo
  • 247
  • 2
  • 13
0

Found an unresolved bug: https://code.google.com/p/selenium/issues/detail?id=6955 - if you can, please provide a test case, primarily a reduced host page with minimal scripts where the problem still occurs so it can be repeated reliably and traced down.

Sometimes I question myself if Google uses their own tools at all.... they should have run into that bug ages ago considering how huge that company is.

user1050755
  • 11,218
  • 4
  • 45
  • 56