Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Qleoz12/b1d369905c2107d372ad7e940244a3b3 to your computer and use it in GitHub Desktop.
Save Qleoz12/b1d369905c2107d372ad7e940244a3b3 to your computer and use it in GitHub Desktop.
Selenium Wait For Page Load
public static void waitForPageLoad(WebDriver drv) {
sleep(50); // Make sure new page init has started...
try {
(new WebDriverWait(drv, 5))
.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return ((JavascriptExecutor)d).executeScript("return document.readyState").equals("complete");
}
});
} catch (TimeoutException ex) {
((JavascriptExecutor)drv).executeScript("window.stop();");
sleep(500);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment