Selenium Web driver wait for long time

kushan picture kushan · Feb 15, 2013 · Viewed 21.1k times · Source

Can I wait with Selenium Web Driver for a long time period?

Even though I can set implicitlywait command like below, it doesn't wait the time that I've given.

 driver.manage().timeouts().implicitlyWait(5, TimeUnit.MINUTES);

Is there anything wrong here?

In my case, I need to execute one test case and wait for 4 minutes and then execute the next test case.

I use Java here.

Answer

aimbire picture aimbire · Feb 15, 2013

Considering you need to wait for a particular element i'd do something in the lines of a ExplicitWait like below.

WebDriverWait wait = new WebDriverWait(driver, 300); // The int here is the maximum time in seconds the element can wait.
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("someId")));

On this case you can use any of the ExpectedConditions you'd like. Also not having to use a big wait time on some very particular cases. This imho is a good practice.