views:

354

answers:

1

I've met with strange issue in Selenium RC. When I use IE7 the test works fine. However if I use firefox 3.5, Selenium fetches the page before it completely loaded. Using a thread sleep resolves that matter.

Is there a difference between, how page load flag handled in IE and FireFox?

selenium.setTimeout(Timeout);
selenium.open("http://localhost");
selenium.waitForPageToLoad(Timeout);
selenium.windowMaximize();
selenium.windowFocus();
Thread.sleep(60000);
selenium.type("//html/body/table/tbody/tr[2]/td/div/form/table/tbody/tr[1]/td/table/tbody/tr[3]/td[2]/input","test");   
selenium.type("pwd","test");   
selenium.click("submit");
selenium.waitForPageToLoad(Timeout);        
Thread.sleep(60000);
System.out.println(selenium.getLocation());
System.out.println(selenium.getHtmlSource());
String[] ro=selenium.getAllLinks();
System.out.println("-----"+ro.length);

In IE7 everything works with the thread.sleep, not in FireFox.

+1  A: 

It could be that any JavaScript that runs on page load hasn't completed before your Selenium command is sent. For example, if the input you are attempting to type into is disabled initially then Selenium might be attempting to type into it before the JavaScript that enabled it has completed.

If this is the case, you could try adding an appropriate waitForCondition command in your test, this will continually re-evaluate and continue once the condition is met, which is much better than an arbitrary sleep.

The following example would wait for an element to become enabled:

selenium.waitForCondition("var value = selenium.isEditable('id=myElement'); value == true", "60000");

I would also recommend reviewing your locator, as it's currently a very brittle XPath, and just a slight change to your web application's HTML source could break your test. Try looking for an id attribute and creating your xpath relative to that.

For example if your final table had an id of myTable you could use:

xpath=id('myTable')//tr[3]/td[2]/input
Dave Hunt
May be JavaScript hasn't completely loaded the page. However, I would like to know, is there any difference in the IE and FireFox pageload flag.
Rajasankar
I'd guess that the reason you are seeing differences in IE and Firefox is due to IE being slower at locating via XPath, giving your page enough time to finish loading.
Dave Hunt