Skip to main content

Implicit vs Explicit Waits

Intro

In order to make our Selenium tests resilient, we need to make them wait for certain elements to load. Elements that we want to interact with. This is especially true with JavaScript heavy pages.

But should we be using static sleeps, implicit waits, explicit waits?

Static sleeps are something to be avoided, because they force your tests to wait a hard-coded amount of time to perform an action -- this is not recommended. But what about implicit waits, explicit waits... and what about using them together?

A Solution

The short answer? Use explicit waits.

Adding an implicit wait to your Selenium tests is simple enough and may seem intuitive. But there are cases where it simply doesn't help you like you think it will. And while you can combine explicit and implicit waits together (e.g., override an implicit wait with an explicit wait to make a Selenium action wait longer) -- you shouldn't. I'll discuss more on that later.

Let's continue with some examples.

About The Author

Dave Haeffner is the original writer of Elemental Selenium -- a free, once weekly Selenium tip newsletter that's read by thousands of testing professionals. He also created and maintains the-internet (an open-source web app that's perfect for writing automated tests against).

Dave has helped numerous companies successfully implement automated acceptance testing; including The Motley Fool, ManTech International, Sittercity, and Animoto. He is also an active member of the Selenium project and has spoken at numerous conferences and meetups around the world about automated acceptance testing.

Dave Haeffner profile picture