Issue Details (XML | Word | Printable)

Key: SRC-302
Type: Bug Bug
Status: Open Open
Priority: Minor Minor
Assignee: Andras Hatvani
Reporter: -= vitorg =-
Votes: 10
Watchers: 13
Operations

If you were logged in you would be able to see more operations.
Selenium Remote Control

"Couldn't access document.body" right after waitForPageToLoad

Created: 30/Jul/07 02:07 PM   Updated: Wednesday 12:07 PM
Component/s: Client Driver - Java, Launcher - Firefox
Affects Version/s: 0.9.2
Fix Version/s: None

Issue Links:
Dependency
 


 Description  « Hide

After installing snapshot selenium-remote-control-0.9.2-20070717.182442-51-dist we have some troubles with waitForPageToLoad method.
In most cases calling method isTextPresent right after waitForPageToLoad causes an exception "com.thoughtworks.selenium.SeleniumException: ERROR: Couldn't access document.body. Is this HTML page fully loaded?".
Code like this:
.....
selenium.click("name=Submit"); // this line submits form, so it causes page reloading
selenium.waitForPageToLoad("60000");
selenium.isTextPresent("some text"); // here we have an error
.....

My fix is calling Thread.sleep(500) right after selenium.waitForPageToLoad, it works fine, but it means there some bug in selenium.waitForPageToLoad method.



Sort Order: Ascending order - Click to sort in descending order
Danilo added a comment - 29/Jan/08 03:19 PM

I had this problem too.
Now I'm calling Thread.sleep(500) to solve this bug.


Sebastian Nohn added a comment - 16/Apr/08 08:30 AM

Any idea when this is going to be fixed?


Patrick Ruckstuhl added a comment - 21/May/08 07:51 AM

I also have this problem. In addition I also have problems using waitForPageToLoad in firefox. It might be related to the way we do the requests (click builds a form in a hidden frame which is submitted and has a target of the originating frame.

I solved the problems by doing this

session().getEval("selenium.browserbot.getCurrentWindow().document.selenium_dummy = 'reloading'");
session().click(click);
session().waitForCondition("try {var doc = selenium.browserbot.getCurrentWindow().document;doc.readyState == 'complete' && doc.selenium_dummy == undefined}catch(err){false}", Element.TIMEOUT);


Andras Hatvani added a comment - 04/Sep/08 03:10 PM

Reduced priority as the issue has been reported about a nightly snapshot, which must not be stable. Furthermore, there are workarounds like waiting for a checkpoint element.
Is the error still reproducible with an actual released version, like 0.9.2 AND 1.0 beta 1?


Aaron Goldstein added a comment - 22/Oct/08 08:37 PM

This crops up consistently for me when running Selenium 1.0-beta1 on Linux. I'm using Firefox v2.0.0.17, Selenium server 1.0-beta1, PHP client libraries (with PHP v5.2.5), and JDK v1.6.0_10. Similar to previous posters, I can work around the issue with a sleep. This doesn't happen for me 100% of the time, but it happens frequently enough that my test cases don't work properly. I haven't observed the same issue when running under Windows, using the same version of Selenium, Java and Firefox.


Jean-Charles Meyrignac added a comment - 03/Nov/08 08:38 AM

I had the same exact problem with Selenium 1.0 beta, under Vista.
It seems related to a POST into a frame, and SeleniumRC crashes with this error message (also, I didn't find it in the source !).

Here is an excerpt:

selectFrame navbox
clickAndWait btnOK
selectFrame relative=top
verifyTextPresent message

I get:
Couldn't access document.body.  Is this HTML page fully loaded?
on the last line.
I'll add a function to wait for page completion, since AndWait seems unable to do it correctly.


Jean-Charles Meyrignac added a comment - 03/Nov/08 10:04 AM

I dug onto this problem, and here are some remarks:

1) We can fix it by using the following function:
Selenium.prototype.isBodyReady = function()

{ return !!this.browserbot.getDocument().body; }

and use
waitForBodyReady

2) The problem appears when several pages are loaded simultaneously.
It seems that Selenium Core only catches the first one, and doesn't care about the others.
I think it may be due to some bugs in Selenium Core, since it uses for example getCurrentWindow() to locate a frame in browserbot.js. The correct call is getCurrentWindow(true), in order to avoid clearing the pageLoad flag.
In general, the newPageLoaded flag is incorrectly handled.

3) IMO, I think it's a bug in ReadyState.xpi, which correctly catches when a page is reloaded, but not when it's ready (I mean you can open the document.body).


Andras Hatvani added a comment - 18/Nov/08 02:58 PM

With the following code lines when using the latest snapshot I can't reproduce this issue:

selenium = new DefaultSelenium("127.0.0.1", 5555, "*firefox", "http://www.google.at");
selenium.start();
selenium.open("/");
selenium.type("q", "seleniumhq");
selenium.click("btnG");
selenium.waitForPageToLoad("60000");
selenium.isTextPresent("selenium-ide");

As some of you mentioned frames what about using waitForFrameToLoad()?


Jean-Charles Meyrignac added a comment - 18/Nov/08 03:14 PM

I tried waitForPageToLoad, and waitForFrameToLoad, but they both fail.

As I said, I have to run the test around 3 times to get an error, and the test has around 10 of such tricks.
This means that it fails around 1 out of 30 times.
My configuration is Vista SP1+Firefox 3.
I'll try to create a small test that fails...


Paul Hammant added a comment - 03/Feb/09 09:48 AM

The waitFor/Condition logic in the Java client driver now caters for this (amongst other unexpected SeleniumExceptions). You won't need to code a manual sleep() operation as waitFor will do this functionality silently, and try to recover before timeout.

If the wait/For stuff gets ported to PHP, Python etc, then other languages will see this too.


Thierry added a comment - 10/Feb/09 08:28 AM

I'm seen this error with 1.0 Beta 2. It is very intermittent (like once of every 8 runs). Of course to make things more difficult this is never happening in development but only on the continuous integration server.


Thierry added a comment - 10/Feb/09 11:18 AM

I forgot to mention in my previous comment that we never ran into this problem when running selenium server 0.9.2 (and we had been running it for about a year).
We have seen this problem on a regular basis with 1.0 beta 2, which we have been running for about 3 weeks now on our continuous integration server.


Patrick Lightbody added a comment - 10/Feb/09 11:24 AM

To everyone that is watching this issue: what mode are you running this in? Does it go away if you switch the mode to a different mode?


Thierry added a comment - 10/Feb/09 01:55 PM

Running with chrome mode. Don't have an answer for your question. Which mode should be tried?


Patrick Lightbody added a comment - 10/Feb/09 02:11 PM

Theirry - chrome mode should be fine, but can you try some of the other ones listed here:

http://clearspace.openqa.org/community/selenium/blog/2009/01/13/selenium-rc-beta-2-goodies-and-gotchas

Particularly *firefoxproxy with and without -proxyInjectionMode turned on.


Pavel added a comment - 09/Mar/09 12:06 PM

Getting the same problem with Firefox 3.0.7 and Selenium RC 1.0 beta 2. In my case it fails all the time with any of those modes: *chrome, *firefox, *firefoxproxy. Any suggestion?


Haw-Bin Chai added a comment - 09/Mar/09 02:40 PM

@Pavel: Can you share your test?


Evan Leonard added a comment - 21/Aug/09 12:20 PM

Any progress or movement on this?


Dave Knipp added a comment - 28/Sep/09 12:11 PM

I'm also experiencing this issue with selenium rc 1.0.2 with ff 3.0.13


Agnes added a comment - 12/Oct/09 01:53 AM

I'm seeing a different form of this error with rc 1.0.1 and FF 3.0.x. Instead I get lots of "X is undefined" errors during our tests using the waitForCondition() method.

Cause it is an intermittent failure, it is hard to tell but I think it is when I use the *firefox mode (seems to be ok with *firefoxproxy). I also see this a lot in our automated build system and not as much running the tests locally during development. Like Thierry, we never saw this problem previously when we were on 0.9.2.


Agnes added a comment - 12/Oct/09 01:56 AM

I also forgot to mention we are using singleWindow mode (multi window mode seems to slow down our automated tests).


Ross Patterson added a comment - 10/Mar/10 10:59 AM

We see this as well, running in both *firefox and *iexploreproxy modes. Our work-around has been to wrap IsTextPresent() and to call WaitForCondition("selenium.isElementPresent('document.body');", ...) first. It's a kludge, but it seriously reduces the random-failure count.


Jean-Charles Meyrignac added a comment - 10/Mar/10 11:23 AM

Here is the workaround that we use in our user-extensions.js.
It overloads the makePageLoadCondition in order to wait for the <body> tag to be completely loaded.
Sorry for the ugly try/catch...

Selenium.prototype.makePageLoadCondition = function(timeout) {
if (timeout == null) { timeout = this.defaultTimeout; }
// if the timeout is zero, we won't wait for the page to load before returning
if (timeout == 0) { return; }
return Selenium.decorateFunctionWithTimeout(fnBind(function()
{
try

{ if (this.browserbot.getCurrentWindow(true).document.getElementsByTagName("html")[0].innerHTML.indexOf("<body") < 0) return false; }

catch(ex)

{ return false; }

return this.browserbot.isNewPageLoaded();
}, this), timeout);
};


Evan Leonard added a comment - 10/Mar/10 12:07 PM

Here's what we use:

public static boolean isTextPresentSafe(String text) {
boolean present = false;
try { present = itsBrowser.isTextPresent(text); }
catch (SeleniumException e) {
if(!isSeleniumBugSRC302(e)){ throw e; }
}
return present;
}

/**

  • Hack to work around: http://jira.openqa.org/browse/SRC-302
    */
    private static boolean isSeleniumBugSRC302(Exception e) { String message = e.getMessage(); return message.contains("Couldn't access document.body"); }