I’m developing a test unit with Selenium FirefoxDriver in Java. I’d like some help handling the page load. My problem is waiting for elements while still have a timeout. I already tried applying pageLoadTimeout,implicitlyWait with no success, some methods continue to wait for full page load. A preview of my code:
(...)
FirefoxDriver driver= new FirefoxDriver(firefoxProfile);
driver.manage().timeouts().pageLoadTimeout(1, TimeUnit.MILLISECONDS);
driver.manage().timeouts().implicitlyWait(1, TimeUnit.MILLISECONDS);
try {
driver.get("http://mysite");
} catch (org.openqa.selenium.TimeoutException e) {
//after 1 milisecond get method timeouts
}
for (int i = 0; i < 5; i++) {//5 seconds wait
if (driver.findElements(By.id("wait_id")).size() == 0) { //findElements cause java to wait for full load
debug("not found");//never happens because 'if' condition waits for full load
driver.wait(1000);
} else {
debug("found");
break;
}
}
Thanks in advance.
The
pageLoadTimeout()method only works properly with Firefox run with “unstable load strategy”. Therefore, run yourFirefoxDriverlike this:Note that it only works under Firefox, really is unstable, and could make some of your other tests fail. Use with caution.