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.
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
waitForConditioncommand 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:
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
idattribute and creating your xpath relative to that.For example if your final table had an
idofmyTableyou could use: