tags:

views:

4837

answers:

5

In certain unknown situations selenium does not detect that a page has loaded when using the open method. I am using the Java API. For example (This code will not produce this error. I don't know of an externally visible page that will.):

Selenium browser = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.google.com");
browser.start();
browser.open("http://www.google.com/webhp?hl=en");
browser.type("q", "hello world");

When the error occurs, the call to 'open' times out, even though you can clearly see that the page has loaded successfully before the timeout occurs. Increasing the timeout does not help. The call to 'type' never occurs, no progress is made.

How do you get selenium to recognize that the page has loaded when this error occurs?

+1  A: 

When I do Selenium testing, I wait to see if a certain element is visible (waitForVisible), then I do my action. I usually try to use an element after the one I'm typing in.

James Deville
A: 

Enabling the 'multiWindow' feature solved the issue, though I am not clear why.

SeleniumServer(int port, boolean slowResources, boolean multiWindow)

SeleniumServer server = new SeleniumServer(4444, false, true);

Any clarification would be helpful.

Matthew Jaskula
A: 

I've run into similar issues when using Selenium to test an application with iFrames. Basically, it seemed that once the primary page (the page containing the iframes) was loaded, Selenium was unable to determine when the iframe content had finished loading.

From looking at the source for the link you're trying to load, it looks like there's some Javascript that's creating additional page elements once the page has loaded. I can't be sure, but it's possible that this is what's causing the problem since it seems similar to the situation that I've encountered above.

Do you get the same sort of errors loading a static page? (ie, something with straight html)

If you're unable to get a better answer, try the selenium forums, they're usually quite active and the Selenium devs do respond to good questions.

http://clearspace.openqa.org/community/selenium_remote_control

Also, if you haven't already tried it, add a call to browser.WaitForPageToLoad("15000") after the call to open. I've found that doing this after every page transition makes my tests a little more solid, even though it shouldn't technically be required. (When Selenium detects that the page actually has loaded, it continues, so the actual timeout variable isn't really a concern..

Peter Bernier
+3  A: 

Using 'openAndWait' in place of 'open' will do the trick.

From the website:

Many Actions can be called with the "AndWait" suffix, e.g. "clickAndWait". This suffix tells Selenium that the action will cause the browser to make a call to the server, and that Selenium should wait for a new page to load.

Lawrence
A: 

I have this problem and openAndWait didn't help me. The docs say open does the "AndWait" implicitly.

Dan