Wait for page load in Selenium

JavaSeleniumWebdriverSelenium Webdriver

Java Problem Overview


How do you make Selenium 2.0 wait for the page to load?

Java Solutions


Solution 1 - Java

You can also check pageloaded using following code

IWait<IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(30.00));

 wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));

Solution 2 - Java

Use class WebDriverWait

Also see here

You can expect to show some element. something like in C#:

WebDriver _driver = new WebDriver();
WebDriverWait _wait = new WebDriverWait(_driver, new TimeSpan(0, 1, 0));

_wait.Until(d => d.FindElement(By.Id("Id_Your_UIElement")));

Solution 3 - Java

If you set the implicit wait of the driver, then call the findElement method on an element you expect to be on the loaded page, the WebDriver will poll for that element until it finds the element or reaches the time out value.

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

source: implicit-waits

Solution 4 - Java

In general, with Selenium 2.0 the web driver should only return control to the calling code once it has determined that the page has loaded. If it does not, you can call waitforelemement, which cycles round calling findelement until it is found or times out (time out can be set).

Solution 5 - Java

Ruby implementation:

wait = Selenium::WebDriver::Wait.new(:timeout => 10)
wait.until {
    @driver.execute_script("return document.readyState;") == "complete" 
}

Solution 6 - Java

You may remove the System.out line. It is added for debug purposes.

WebDriver driver_;

public void waitForPageLoad() {

    Wait<WebDriver> wait = new WebDriverWait(driver_, 30);
    wait.until(new Function<WebDriver, Boolean>() {
        public Boolean apply(WebDriver driver) {
            System.out.println("Current Window State       : "
                + String.valueOf(((JavascriptExecutor) driver).executeScript("return document.readyState")));
            return String
                .valueOf(((JavascriptExecutor) driver).executeScript("return document.readyState"))
                .equals("complete");
        }
    });
}

Solution 7 - Java

All of these solutions are OK for specific cases, but they suffer from at least one of a couple of possible problems:

  1. They are not generic enough -- they want you to know, ahead of time, that some specific condition will be true of the page you are going to (eg some element will be displayed)

  2. They are open to a race condition where you use an element that is actually present on the old page as well as the new page.

Here's my attempt at a generic solution that avoids this problem (in Python):

First, a generic "wait" function (use a WebDriverWait if you like, I find them ugly):

def wait_for(condition_function):
    start_time = time.time()
    while time.time() < start_time + 3:
        if condition_function():
            return True
        else:
            time.sleep(0.1)
    raise Exception('Timeout waiting for {}'.format(condition_function.__name__))

Next, the solution relies on the fact that selenium records an (internal) id-number for all elements on a page, including the top-level <html> element. When a page refreshes or loads, it gets a new html element with a new ID.

So, assuming you want to click on a link with text "my link" for example:

old_page = browser.find_element_by_tag_name('html')

browser.find_element_by_link_text('my link').click()

def page_has_loaded():
    new_page = browser.find_element_by_tag_name('html')
    return new_page.id != old_page.id

wait_for(page_has_loaded)

For more Pythonic, reusable, generic helper, you can make a context manager:

from contextlib import contextmanager

@contextmanager
def wait_for_page_load(browser):
    old_page = browser.find_element_by_tag_name('html')

    yield

    def page_has_loaded():
        new_page = browser.find_element_by_tag_name('html')
        return new_page.id != old_page.id

    wait_for(page_has_loaded)

And then you can use it on pretty much any selenium interaction:

with wait_for_page_load(browser):
    browser.find_element_by_link_text('my link').click()

I reckon that's bulletproof! What do you think?

More info in a blog post about it here

Solution 8 - Java

Here is a Java 8 version of the currently most upvoted answer:

WebDriverWait wait = new WebDriverWait(myDriver, Duration.ofSeconds(15));
wait.until(webDriver -> "complete".equals(((JavascriptExecutor) webDriver)
    .executeScript("return document.readyState")));
	

Where myDriver is a WebDriver object (declared earlier).

Note: Be aware that this method (document.readyState) only checks the DOM.

Solution 9 - Java

You can also use the class: ExpectedConditions to explicitly wait for an element to show up on the webpage before you can take any action further actions

You can use the ExpectedConditions class to determine if an element is visible:

WebElement element = (new WebDriverWait(getDriver(), 10)).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input#houseName")));

See ExpectedConditions class Javadoc for list of all conditions you are able to check.

Solution 10 - Java

Imran's answer rehashed for Java 7:

	WebDriverWait wait = new WebDriverWait(driver, 30);
	
	wait.until(new ExpectedCondition<Boolean>() {
		public Boolean apply(WebDriver wdriver) {
			return ((JavascriptExecutor) driver).executeScript(
				"return document.readyState"
			).equals("complete");
		}
	});

Solution 11 - Java

This seems to be a serious limitation of WebDriver. Obviously waiting for an element will not imply the page being loaded, in particular the DOM can be fully build (onready state) whereby JS is still executing and CSS and images are still loading.

I believe the simplest solution is to set a JS variable upon the onload event after everything is initialized and check and wait for this JS variable in Selenium.

Solution 12 - Java

If you want to wait for a specific element to load, you can use the isDisplayed() method on a RenderedWebElement :

// Sleep until the div we want is visible or 5 seconds is over
long end = System.currentTimeMillis() + 5000;
while (System.currentTimeMillis() < end) {
    // Browsers which render content (such as Firefox and IE) return "RenderedWebElements"
    RenderedWebElement resultsDiv = (RenderedWebElement) driver.findElement(By.className("gac_m"));

    // If results have been returned, the results are displayed in a drop down.
    if (resultsDiv.isDisplayed()) {
      break;
    }
}

(Example from The 5 Minute Getting Started Guide)

Solution 13 - Java

Man all these answers require too much code. This should be a simple thing as its pretty common.

Why not just inject some simple Javascript with the webdriver and check. This is the method I use in my webscraper class. The Javascript is pretty basic even if you don't know it.

def js_get_page_state(self):        
    """
    Javascript for getting document.readyState
    :return: Pages state.
    
    More Info: https://developer.mozilla.org/en-US/docs/Web/API/Document/readyState
    """
    ready_state = self.driver.execute_script('return document.readyState')
    if ready_state == 'loading':
        self.logger.info("Loading Page...")
    elif ready_state == 'interactive':
        self.logger.info("Page is interactive")
    elif ready_state == 'complete':
        self.logger.info("The page is fully loaded!")
    return ready_state

Solution 14 - Java

Explicitly wait or conditional wait in this wait until given this condition.

WebDriverWait wait = new WebDriverWait(wb, 60);
wait.until(ExpectedConditions.elementToBeClickable(By.name("value")));

This will wait for every web element for 60 seconds.

Use implicitly wait for wait of every element on page till that given time.

driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

This will wait for every web element for 60 seconds.

Solution 15 - Java

I'm surprised that predicates weren't the first choice as you typically know what element(s) you will next interact with on the page you're waiting to load. My approach has always been to build out predicates/functions like waitForElementByID(String id) and waitForElemetVisibleByClass(String className), etc. and then use and reuse these wherever I need them, be it for a page load or page content change I'm waiting on.

For example,

In my test class:

driverWait.until(textIsPresent("expectedText");

In my test class parent:

protected Predicate<WebDriver> textIsPresent(String text){
    final String t = text;
    return new Predicate<WebDriver>(){
        public boolean apply(WebDriver driver){
            return isTextPresent(t);
        }
    };
}

protected boolean isTextPresent(String text){
    return driver.getPageSource().contains(text);
}

Though this seems like a lot, it takes care of checking repeatedly for you and the interval for how often to check can be set along with the ultimate wait time before timing out. Also, you will reuse such methods.

In this example, the parent class defined and initiated the WebDriver driver and the WebDriverWait driverWait.

I hope this helps.

Solution 16 - Java

Use implicitly wait for wait of every element on page till given time.

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

this wait for every element on page for 30 sec.

Another wait is Explicitly wait or conditional wait in this wait until given condition.

WebDriverWait wait = new WebDriverWait(driver, 40);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));

In id give static element id which is diffidently display on the page, as soon as page is load.

Solution 17 - Java

The best way to wait for page loads when using the Java bindings for WebDriver is to use the Page Object design pattern with PageFactory. This allows you to utilize the AjaxElementLocatorFactory which to put it simply acts as a global wait for all of your elements. It has limitations on elements such as drop-boxes or complex javascript transitions but it will drastically reduce the amount of code needed and speed up test times. A good example can be found in this blogpost. Basic understanding of Core Java is assumed.

http://startingwithseleniumwebdriver.blogspot.ro/2015/02/wait-in-page-factory.html

Solution 18 - Java

NodeJS Solution:

In Nodejs you can get it via promises...

If you write this code, you can be sure that the page is fully loaded when you get to the then...

driver.get('www.sidanmor.com').then(()=> {
    // here the page is fully loaded!!!
    // do your stuff...
}).catch(console.log.bind(console));

If you write this code, you will navigate, and selenium will wait 3 seconds...

driver.get('www.sidanmor.com');
driver.sleep(3000);
// you can't be sure that the page is fully loaded!!!
// do your stuff... hope it will be OK...

From Selenium Documentation (Nodejs):

> > this.get( url ) → Thenable<undefined> > > Schedules a command to navigate to the given URL. > > Returns a promise that will be resolved when the document has finished loading.

Solution 19 - Java

You can use the below existing method to set the pageLoadTimeout. In below example if the page is taking more than 20 seconds to load, then it will throw an exception of page reload:

WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);

Solution 20 - Java

Call below Function in your script , this will wait till page is not loaded using javascript

public static boolean isloadComplete(WebDriver driver)
{
    return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("loaded")
            || ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete");
}

Solution 21 - Java

SeleniumWaiter:

import com.google.common.base.Function;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.WebDriverWait;

public class SeleniumWaiter {

      private WebDriver driver;

      public SeleniumWaiter(WebDriver driver) {
           this.driver = driver;
      }

      public WebElement waitForMe(By locatorname, int timeout){
           WebDriverWait wait = new WebDriverWait(driver, timeout);
           return wait.until(SeleniumWaiter.presenceOfElementLocated(locatorname));
      }

      public static Function<WebDriver, WebElement> presenceOfElementLocated(final By locator) {
            // TODO Auto-generated method stub
            return new Function<WebDriver, WebElement>() {
                 @Override
                 public WebElement apply(WebDriver driver) {
                      return driver.findElement(locator);
                 }
            };
      }
 }

And to you use it:

_waiter = new SeleniumWaiter(_driver);

try {
   _waiter.waitForMe(By.xpath("//..."), 10);
} 
catch (Exception e) {
   // Error
}

Solution 22 - Java

/**
 * Call this method before an event that will change the page.
 */
private void beforePageLoad() {
	JavascriptExecutor js = (JavascriptExecutor) driver;
	js.executeScript("document.mpPageReloaded='notYet';");
}

/**
 * Call this method after an event that will change the page.
 * 
 * @see #beforePageLoad
 * 
 *      Waits for the previous page to disappear.
 */
private void afterPageLoad() throws Exception {
	(new WebDriverWait(driver, 10)).until(new Predicate<WebDriver>() {

		@Override
		public boolean apply(WebDriver driver) {
			JavascriptExecutor js = (JavascriptExecutor) driver;
			Object obj = js.executeScript("return document.mpPageReloaded;");
			if (obj == null) {
				return true;
			}
			String str = (String) obj;
			if (!str.equals("notYet")) {
				return true;
			}
			return false;
		}
	});
}

You can change from the document to an element, in the case of where only part of a document is being changed.

This technique was inspired by the answer from sincebasic.

Solution 23 - Java

You can explicitly wait for an element to show up on the webpage before you can take any action (like element.click()):

driver.get("http://somedomain/url_that_delays_loading");
WebElement myDynamicElement = (new WebDriverWait(driver, 10))
    .until(new ExpectedCondition<WebElement>() {
    	@Override
    	public WebElement apply(WebDriver d) {
  		    return d.findElement(By.id("myDynamicElement"));
        }
    }
);

This is what I used for a similar scenario and it works fine.

Solution 24 - Java

My simple way:

long timeOut = 5000;
	long end = System.currentTimeMillis() + timeOut;
		
		while (System.currentTimeMillis() < end) {
			
			if (String.valueOf(
					((JavascriptExecutor) driver)
							.executeScript("return document.readyState"))
					.equals("complete")) {
				break;
			}
		}

Solution 25 - Java

The best way I've seen is to utilize the stalenessOf ExpectedCondition, to wait for the old page to become stale.

Example:

WebDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, 10);

WebElement oldHtml = driver.findElement(By.tagName("html"));
wait.until(ExpectedConditions.stalenessOf(oldHtml));

It'll wait for ten seconds for the old HTML tag to become stale, and then throw an exception if it doesn't happen.

Solution 26 - Java

I use node + selenium-webdriver(which version is 3.5.0 now). what I do for this is:

var webdriver = require('selenium-webdriver'),
    driver = new webdriver.Builder().forBrowser('chrome').build();
;
driver.wait(driver.executeScript("return document.readyState").then(state => {
  return state === 'complete';
}))

Solution 27 - Java

You can use wait. there are basically 2 types of wait in selenium

  • Implicit wait
  • Explicit wait

- Implicit wait

This is very simple please see syntax below:

driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

- Explicit wait

Explicitly wait or conditional wait in this wait until given condition is occurred.

WebDriverWait wait = new WebDriverWait(driver, 40);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));

You can use other properties like visblityOf(), visblityOfElement()

Solution 28 - Java

If someone uses selenide:

public static final Long SHORT_WAIT = 5000L; // 5 seconds
$("some_css_selector").waitUntil(Condition.appear, SHORT_WAIT);

More Conditions can be found here: http://selenide.org/javadoc/3.0/com/codeborne/selenide/Condition.html

Solution 29 - Java

In my case , I used the following to know the page load status. In our application loading gif(s) are present and, I listen to them as follows to eliminate unwanted wait time in the script.

public static void processing(){ 
    WebDriverWait wait = new WebDriverWait(driver, 30);
	wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@id='Msgpanel']/div/div/img")));
	wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//div[@id='Msgpanel']/div/div/img")));
}

Where the xpath locates the gif in the HTML DOM. After this, You may also implement your action methods Click.

public static void click(WebElement elementToBeClicked){
    WebDriverWait wait = new WebDriverWait(driver, 45);
    wait.until(ExpectedConditions.visibilityOf(element));
	wait.until(ExpectedConditions.elementToBeClickable(element)); 
    wait.ignoring(NoSuchElementException.class).ignoring(StaleElementReferenceException.class); elementToBeClicked.click(); 
 }

Solution 30 - Java

How to get Selenium to wait for page load after a click provides the following interesting approach:

  1. Store a reference to a WebElement from the old page.
  2. Click the link.
  3. Keep on invoking operations on the WebElement until StaleElementReferenceException is thrown.

Sample code:

WebElement link = ...;
link.click();
new WebDriverWait(webDriver, timeout).until((org.openqa.selenium.WebDriver input) ->
{
    try
    {
        link.isDisplayed();
        return false;
    }
    catch (StaleElementReferenceException unused)
    {
        return true;
    }
});

Solution 31 - Java

You can use this snippet of code for the page to load:

    IWait wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver,TimeSpan.FromSeconds(30.00));
wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));

Or you can use waiter for any element to be loaded and become visible/clickable on that page, most probably which is going to be load at the end of loading like:

    Wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath(xpathOfElement));
var element = GlobalDriver.FindElement(By.XPath(xpathOfElement));
var isSucceededed = element != null;

Solution 32 - Java

driver.asserts().assertElementFound("Page was not loaded",
By.xpath("//div[@id='actionsContainer']"),Constants.LOOKUP_TIMEOUT);

Solution 33 - Java

The easiest way is just wait for some element which will appear on loaded page.

If you would like to click on some button already after page is loaded you could use await and click:

await().until().at.most(20, TimeUnit.Seconds).some_element.isDisplayed(); // or another condition
getDriver().find(some_element).click;

Solution 34 - Java

  1. WebDriver driver = new ff / chrome / anyDriverYouWish(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); Waits maximum of 10 Seconds.

  2. WebDriverWait wait = new WebDriverWait(driver, 10); wait.until(ExpectedConditions.visibilityOf(WebElement element));

  3. FluentWait<Driver> fluentWait; fluentWait = new FluentWait<>(driver).withTimeout(30, TimeUnit.SECONDS) .pollingEvery(200, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class);

The advantage of the last option is that you can include exception to be expected, so that your execution continues.

Solution 35 - Java

use a if condition and for any of the element present

try {
    Thread.sleep(1000);
} catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

Solution 36 - Java

For implicit wait you can use something like following:

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS)

In order for webpage to wait for a specific object to be visible or cerntain condition to be true. You can use wait feather of web driver.

//120 is maximum number of seconds to wait.
WebDriverWait wait = new WebDriverWait(driver,120);	 
wait.until(ExpectedConditions.elementToBeClickable("CONDITITON"));

In Java, another option is to sleep the thread for specific time.

Thread.sleep(numberOfSeconds*1000); 
//This line will cause thread to sleep for seconds as variable

I created a method to simplify thread.sleep method

public static void wait_time(int seconds){
    try {
	    Thread.sleep(seconds*1000);
	    }catch (InterruptedException e) {
	    // TODO Auto-generated catch block
		    e.printStackTrace();
	    }
}

Use the method as wait_time(10); The thread will sleep for 10 seconds.

Solution 37 - Java

You can try this code to let the page load completely until element is found.

public void waitForBrowserToLoadCompletely() {
	String state = null;
	String oldstate = null;
	try {
		System.out.print("Waiting for browser loading to complete");
		
		int i = 0;
		while (i < 5) {
			Thread.sleep(1000);
			state = ((JavascriptExecutor) driver).executeScript("return document.readyState;").toString();
			System.out.print("." + Character.toUpperCase(state.charAt(0)) + ".");
			if (state.equals("interactive") || state.equals("loading"))
				break;
			/*
			 * If browser in 'complete' state since last X seconds. Return.
			 */

			if (i == 1 && state.equals("complete")) {
				System.out.println();
				return;
			}
			i++;
		}
		i = 0;
		oldstate = null;
		Thread.sleep(2000);

		/*
		 * Now wait for state to become complete
		 */
		while (true) {
			state = ((JavascriptExecutor) driver).executeScript("return document.readyState;").toString();
			System.out.print("." + state.charAt(0) + ".");
			if (state.equals("complete"))
				break;

			if (state.equals(oldstate))
				i++;
			else
				i = 0;
			/*
			 * If browser state is same (loading/interactive) since last 60
			 * secs. Refresh the page.
			 */
			if (i == 15 && state.equals("loading")) {
				System.out.println("\nBrowser in " + state + " state since last 60 secs. So refreshing browser.");
				driver.navigate().refresh();
				System.out.print("Waiting for browser loading to complete");
				i = 0;
			} else if (i == 6 && state.equals("interactive")) {
				System.out.println(
						"\nBrowser in " + state + " state since last 30 secs. So starting with execution.");
				return;
			}

			Thread.sleep(4000);
			oldstate = state;

		}
		System.out.println();

	} catch (InterruptedException ie) {
		ie.printStackTrace();
	}
}

Solution 38 - Java

private static void checkPageIsReady(WebDriver driver) {
	JavascriptExecutor js = (JavascriptExecutor) driver;

	// Initially bellow given if condition will check ready state of page.
	if (js.executeScript("return document.readyState").toString().equals("complete")) {
		System.out.println("Page Is loaded.");
		return;
	}

	// This loop will rotate for 25 times to check If page Is ready after
	// every 1 second.
	// You can replace your value with 25 If you wants to Increase or
	// decrease wait time.
	for (int i = 0; i < 25; i++) {
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
		}
		// To check page ready state.
		if (js.executeScript("return document.readyState").toString().equals("complete")) {
			break;
		}
	}
}

Solution 39 - Java

use following code it's very easy and simple for page load.

public void PageLoad(IWebDriver driver, By by)
{
    try
    {
        Console.WriteLine("PageLoad" + by);
        WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
        wait.Until(ExpectedConditions.ElementIsVisible(by));
        wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30)); // 30 seconds wait until element not found. 
        wait.Until(ExpectedConditions.ElementToBeClickable(by));
        

    }
    catch (Exception ex)
    {

        Console.WriteLine(ex.Message);
        Assert.Fail("Element not found!")
    }
}

i hope this helps you.

Solution 40 - Java

public static int counter = 0;

public void stepGeneralWait() {

    boolean breakIt = true;

    while (true) {
        breakIt = true;
        try {

            do{
                // here put e.g. your spinner ID
                Controller.driver.findElement(By.xpath("//*[@id='static']/div[8]/img")).click();
                Thread.sleep(10000);

                counter++;

                if (counter > 3){
                    breakIt = false;

                }
            }
            while (breakIt);



        } catch (Exception e) {
            if (e.getMessage().contains("element is not attached")) {
                breakIt = false;
            }
        }
        if (breakIt) {
            break;
        }

    }

    try {
        Thread.sleep(12000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

Solution 41 - Java

For Programmers using java 8 onward can use below code to wait for page load using explicit wait.

JavascriptExecutor js = (JavascriptExecutor) driver;  
new WebDriverWait(driver, 10).until(webDriver ->
(js).executeScript("return document.readyState;").equals("complete"));

Note: In my above code Lambda Expression is used, which is only available in java 8 onward version.

For Programmers using lower version of Java i.e. below Java 8 can use:

ExpectedCondition<Boolean> cond = new ExpectedCondition<Boolean>() {
	@Override
	public Boolean apply(WebDriver input) {
		JavascriptExecutor js = (JavascriptExecutor) driver; 
		return js.executeScript("return document.readyState;").equals("complete");
			}
		};
		 
	new WebDriverWait(driver, 100).until(cond);

Solution 42 - Java

Use this function

public void waitForPageLoad(ChromeDriver d){
    	String s="";
    	while(!s.equals("complete")){
    	s=(String) d.executeScript("return document.readyState");
    	try {
    		Thread.sleep(1000);
    	} catch (InterruptedException e) {
    		// TODO Auto-generated catch block
    		e.printStackTrace();
    	}
    	}
    	
    }

Solution 43 - Java

Use:

driver.manage().timeOuts().implicitlyWait(10, TimeUnit.SECONDS);

Which means any search for the elements on the web page could take time to load. The implicitlyWait is set before throwing an exception. The TimeUnit displays whichever way you want to wait in (seconds, minutes, hours and days).

Solution 44 - Java

There are 2 types of waits available in Webdriver/Selenium 2 software testing tool. One of them is Implicit wait and another one is explicit wait. Both (Implicit wait and explicit wait) are useful for waiting in WebDriver. Using waits, we are telling WebDriver to wait for a certain amount of time before going to next step.You can use implicit wait for page load waiting.

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

Solution 45 - Java

I don't think an implicit wait is what you want. Try this:

driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);

More information in the documentation

Solution 46 - Java

This code will wait until all the elements on the page are loaded in the DOM.

WebDriver driver = new WebDriver();
WebDriverWait wait = new WebDriverWait(driver, timeout);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*")));

Solution 47 - Java

In python, you can simply use:

driver.implicitly_wait(30)

Solution 48 - Java

Implicit and explicit wait is better.

But if you are handling an exception in Java, then you can use this for waiting for a page to reload:

Thead.sleep(1000);

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionkarthick kumarView Question on Stackoverflow
Solution 1 - JavaImranView Answer on Stackoverflow
Solution 2 - JavaArtemView Answer on Stackoverflow
Solution 3 - JavaSamView Answer on Stackoverflow
Solution 4 - JavaPaul HadfieldView Answer on Stackoverflow
Solution 5 - JavaallenhwkimView Answer on Stackoverflow
Solution 6 - JavaQIKHANView Answer on Stackoverflow
Solution 7 - JavahwjpView Answer on Stackoverflow
Solution 8 - JavaBelovedFoolView Answer on Stackoverflow
Solution 9 - JavaTedEdView Answer on Stackoverflow
Solution 10 - JavaFinView Answer on Stackoverflow
Solution 11 - JavasibidibaView Answer on Stackoverflow
Solution 12 - JavaTristanView Answer on Stackoverflow
Solution 13 - JavapAulseperformanceView Answer on Stackoverflow
Solution 14 - JavaAnuj TeotiaView Answer on Stackoverflow
Solution 15 - JavaJack MasonView Answer on Stackoverflow
Solution 16 - JavaKuldeep YadavView Answer on Stackoverflow
Solution 17 - JavasonhuView Answer on Stackoverflow
Solution 18 - JavasidanmorView Answer on Stackoverflow
Solution 19 - JavaArpan SainiView Answer on Stackoverflow
Solution 20 - JavaShubham JainView Answer on Stackoverflow
Solution 21 - Javatux23View Answer on Stackoverflow
Solution 22 - JavaMarcView Answer on Stackoverflow
Solution 23 - JavaanirusView Answer on Stackoverflow
Solution 24 - JavaRichardKView Answer on Stackoverflow
Solution 25 - JavaforresthopkinsaView Answer on Stackoverflow
Solution 26 - JavayuwanlinView Answer on Stackoverflow
Solution 27 - Javaiamsankalp89View Answer on Stackoverflow
Solution 28 - JavaIKoView Answer on Stackoverflow
Solution 29 - JavaPraveenView Answer on Stackoverflow
Solution 30 - JavaGiliView Answer on Stackoverflow
Solution 31 - JavaMohsin AwanView Answer on Stackoverflow
Solution 32 - JavaRan AdlerView Answer on Stackoverflow
Solution 33 - JavaMichauView Answer on Stackoverflow
Solution 34 - JavaVinod Kumar K VView Answer on Stackoverflow
Solution 35 - Javaiam_muqshidView Answer on Stackoverflow
Solution 36 - JavaSalman ArshadView Answer on Stackoverflow
Solution 37 - JavaANarulaView Answer on Stackoverflow
Solution 38 - JavaPrasobh.KollattuView Answer on Stackoverflow
Solution 39 - JavaNeel GurbaniView Answer on Stackoverflow
Solution 40 - JavaFiras Al-BarghouthiView Answer on Stackoverflow
Solution 41 - JavaMD TARIQUEView Answer on Stackoverflow
Solution 42 - JavaManavendherView Answer on Stackoverflow
Solution 43 - JavavageeshwarView Answer on Stackoverflow
Solution 44 - JavaGulraiz AslamView Answer on Stackoverflow
Solution 45 - JavaanthonyjruffaView Answer on Stackoverflow
Solution 46 - Javarahul yadavView Answer on Stackoverflow
Solution 47 - JavaAk8511View Answer on Stackoverflow
Solution 48 - JavaVaibhavView Answer on Stackoverflow