A rule of thumb for using wait() would be before navigating to a different page. For Ex :

WebDriverWait(driver,10).until(lambda driver: driver.title.startswith("Submitted!!"))

What would be other such instances where using wait() would be a good coding practice?

I ask because i have experienced that when my test scripts don't work i just stick in a wait() for elements/pages to load . However i don't want to introduce a wait() after every webdriver action because that would increase the test time.

So in your experience , what are the best practices to using wait() ?

  • 1
    +1 This question applies to more than just Selenium/Webdriver. Jul 11, 2012 at 20:57
  • Yes I thought so but could not find a tag for 'coding practices' or 'best practices' Jul 11, 2012 at 21:00

3 Answers 3


You want to wait whenever there's a condition that must be satisfied before the test case can proceed. Waiting for a page to load is one such condition; another might be waiting for an AJAX interaction to finish, or for an error message to display.

Sticking a wait() after every action is not productive. Sticking a wait before every action that must occur before another action can safely be performed is.


As the WebdriverWait only waits until your expected condition is satisfied, I dont think your test will get delayed if your AUT's page and its elements get loaded on time.

  • 1
    Right, but still it would not be good practice too use explicit waits after every webdriver action (which includes some implicit wait already). It is not necessary for a lot of actions and would just clutter the code, making it hard to read.
    – zpea
    Jul 11, 2012 at 11:31
  • The following are the type of waits i said about, it waits until the expectation is met new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.name("btnG"))); new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.name("btnG"))); driver.findElement(By.name("btnG")).click(); new WebDriverWait(driver, 3).until(ExpectedConditions.titleIs("webdriver - Google Search")); Jul 18, 2012 at 5:47

In selenium you can set a 'sticky wait' for the session:


Mark Smith.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.