#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →

Implicit Waits vs Explicit Waits

Why Waits Are Necessary

Modern web pages load content asynchronously, meaning elements may not be immediately available when a script tries to interact with them. Waits tell Selenium to pause intelligently until elements are ready, preventing flaky test failures.

Implicit Waits

An implicit wait applies a single default wait time across the entire script - Selenium will keep polling for an element up to that timeout before throwing an error, whenever any element lookup is performed.

Explicit Waits

An explicit wait targets a specific element and condition, such as waiting until it becomes clickable or visible, rather than applying a blanket timeout everywhere. This makes tests more precise and often faster overall.

Implicit vs Explicit at a Glance

AspectImplicit WaitExplicit Wait
ScopeApplies globally to all lookupsApplies to a specific element/condition
FlexibilityLow - one fixed timeoutHigh - custom conditions per element
Recommended UseSimple scripts, quick setupReal-world, production-grade tests

Avoiding Mixed Waits

Mixing implicit and explicit waits in the same script can cause unpredictable, inconsistent timeout behavior. Most experienced Selenium users pick one strategy - typically explicit waits - and stick with it consistently.

Explicit waits are usually implemented through Selenium's WebDriverWait class, which deserves a closer look.

Writing Both Waits in Selenium 4 (Java)

An implicit wait is set once, usually right after creating the driver:

WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
driver.findElement(By.id("username")).sendKeys("demo");

An explicit wait is created where you need it and given a condition:

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

WebElement submit = wait.until(
    ExpectedConditions.elementToBeClickable(By.id("submit")));
submit.click();

wait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector(".spinner")));
wait.until(ExpectedConditions.urlContains("/dashboard"));

Selenium 4 uses Duration objects; the older constructors that took a plain number of seconds are deprecated. Python offers the same tools through WebDriverWait and the expected_conditions module.

What Happens While Selenium Waits

  1. The explicit wait checks the condition immediately.
  2. If the condition is not met, it sleeps for the polling interval, which is half a second by default, and checks again.
  3. Exceptions such as NoSuchElementException during these checks are ignored, so the wait keeps trying.
  4. As soon as the condition returns a value, the wait stops and returns it, so a fast page is not slowed down.
  5. If the timeout passes first, a TimeoutException is thrown with a message describing the condition.

An implicit wait works differently: it only affects findElement and findElements, and only waits for presence in the DOM. It cannot wait for an element to become visible, enabled or clickable.

Why Mixing Them Causes Strange Timeouts

Suppose the implicit wait is 10 seconds and you use an explicit wait of 15 seconds for a spinner to disappear. Each poll of the explicit wait calls findElement, and that call itself may block for up to 10 seconds. The total wait can stretch far beyond what either setting suggests, and the exact time varies by driver. Waiting for something to disappear is the worst case, because every lookup for a missing element waits the full implicit time.

The practical fix is simple: keep the implicit wait at zero and use explicit waits everywhere, ideally through a small helper method so tests stay short.

Choosing a Wait and Mistakes to Avoid

SituationBest choice
Element appears after an AJAX callExplicit wait for visibility
Button enabled after a form becomes validExplicit wait for clickability
Custom rule, such as text changing to "Done"FluentWait or a lambda condition
Quick throwaway scriptImplicit wait is acceptable
  • Using Thread.sleep() to fix flakiness; it always waits the full time and still fails on a slow day.
  • Setting very long timeouts that hide real performance problems.
  • Waiting for presence when the test really needs visibility or clickability.

Ready to master Selenium Training Course?

Join Uncodemy's hands-on training and build real automation skills with expert mentors.

Explore Course