4

I have set my implicit wait to 10 secs when my driver is created. When I wish to use explicit wait, do I have to set implicit wait to 0?

Here is a sample:

WebDriver webDriver = new FirefoxDriver();
webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//Now I want to use Explicit wait

Do I have to do webDriver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); or it is not necessary?

WebDriverWait wait = new WebDriverWait(webDriver, WAIT_FOR_TIMEOUT_SEC);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(id)));
1
  • This question looks fine in its current state. Commented Oct 5, 2015 at 15:29

1 Answer 1

7

It's not necessary to re-declare implicit wait time back to zero.

Reason: When you say that you want to use an explicit wait, it only means that your implicit wait time isn't enough to wait for the element to appear and so you declare an explicit wait after a particular action.

When Should you use an Implicit wait: Implicit wait is a way to tell selenium to wait for a particular period of time after executing each and every action. This helps in synchronisation of most actions that you perform. The longer time you give the slower your test executes. More about implicit wait

When Should you use an Explicit wait: Explicit wait is used when a particular action takes time to perform or load on to the DOM. This does not tell selenium to wait for a particular time after each and every action but instead tells selenium to wait for a period of time before executing a particular action only. More about explicit wait

WARNING from Selenium Website: Do not mix implicit and explicit waits. Doing so can cause unpredictable wait times. For example setting an implicit wait of 10s and an explicit wait of 15 seconds, could cause a timeout to occur after 20 seconds.

Hope it helps.

Sign up to request clarification or add additional context in comments.

4 Comments

Do you mean that when we use an explicit wait, it cancels out the effect of implicit wait?
@Rameshwar No, it doesn't cancel that effect. It adds to it, not accurately though. But it does increase the wait time a little more so that webdriver gets more time to poll for the element to appear. Updated answer to include your query.
What if my implicit wait is 10 secs and explicit wait is 5 secs, And the awaited element appeared at 7th seconds? Will my explicit wait through timeout exception?
Selenium checks if the ExpectedCondition is met during both implicit and explicit timeouts by polling at specified time intervals. If its not found, then it throws error. If its found then waits will be skipped. So there's always an ambiguity when you use both together. So, if your element appears at 7th sec, it'll stop waiting for the element based on the time it appears and skip both implicit and explicit waits or just one of them. Though it'll execute the explicit wait command, but since the element is already present selenium will not wait for anything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.