The Sauce Labs Cookbook

Sauce Headless

Front End Performance Testing


External Resources

More Info

Page tree
Skip to end of metadata
Go to start of metadata

Test scripts sometimes run ahead of the website or application under test, returning errors in the process. For example, when testing dynamic content that takes five seconds to load after a click, your script could fail unless you tell it to pause before the next interactive element appears. The Selenium community generally recommends using explicit waits to solve this problem.

While you could also use implicit waits, explicit waits can be set to wait for broader conditions. Selenium guru Dave Haeffner provides an excellent example of why you should use explicit waits on his Elemental Selenium blog. Whether you use explicit or implicit waits, you should not mix the two types in the same test. 

Scripting Examples

These code samples, from the SeleniumHQ documentation on explicit and implicit waits, show how you might use an explicit wait in your tests. In their words, this sample shows how you would use an explicit wait that "waits up to 10 seconds before throwing a TimeoutException, or, if it finds the element, will return it in 0 - 10 seconds. WebDriverWait by default calls the ExpectedCondition every 500 milliseconds until it returns successfully. A successful return for ExpectedCondition type is Boolean return true, or a not null return value for all other ExpectedCondition types."