Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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() ?

share|improve this question
1  
+1 This question applies to more than just Selenium/Webdriver. –  joshin4colours Jul 11 '12 at 20:57
    
Yes I thought so but could not find a tag for 'coding practices' or 'best practices' –  user1411110 Jul 11 '12 at 21:00

3 Answers 3

up vote 5 down vote accepted

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.

share|improve this answer

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

driver.implicitly_wait(10)

Mark Smith.

share|improve this answer

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.

share|improve this answer
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 '12 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")); –  Rakesh Prabhakaran Jul 18 '12 at 5:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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