I have been using a java-script wait condition to wait for page load and my code is like this:
public void untilPageIsLoaded() {
ExpectedCondition<Boolean> condition = new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete");
}
};
WebDriverWait wait = new WebDriverWait(driver, timeout);
wait.until(condition);
}
Initially this code was working very well but few days later my tests started getting stuck at random points. So I investigated the issue and came to know that the culprit is above java-script wait condition which stops execution.
Even I was not getting any exception and it never timeout.I know this is very strange but this is not only with me, have a look here;
https://code.google.com/p/selenium/issues/detail?id=6955
I tried with Upgraded/downgraded version of selenium and browser,changed system configuration but none of them worked.
Now I want to replace above java-script wait condition with some other code.I don't want to use thread.sleep();
Please suggest me something good.