Wait for Page Load in Selenium


Wait for Page Load in Selenium

Oftenly it is found that automation engineer faces challenges to make sure that page has been loaded completely. how to deal with Ajax and Jquery calls. In this post, we will see how we can ensure that page is completely loaded.

we mainly encounter with below operations on the webpage which creates an uncertainty to get/ find complete page load.

  • Ajax/ Javascript
  • Jquery

I have written below code for each of cases, it will help you to handle page load for Ajax and Jquery.


Javascript to find the page load completely
void waitForLoad(WebDriver driver) {
 new WebDriverWait(driver, 30).until((ExpectedCondition<Boolean>) wd -> ((JavascriptExecutor) wd).executeScript("return document.readyState").equals("complete"));
 System.out.println("Page Loaded Completely");
Jquery to find the Jquery has been completely executed
 public void waitForJQuery(WebDriver driver) {
 (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
 public Boolean apply(WebDriver d) {
 JavascriptExecutor js = (JavascriptExecutor) d;
 return (Boolean) js.executeScript("return !!window.jQuery && window.jQuery.active == 0");


I hope you will get help of above codesnipts.

Leave A Comment