Skip to content
SDETRole
SDETRole

Glossary · UI automation

Explicit wait

Also called: explicit waits, WebDriverWait, FluentWait

Definition

A wait that polls for one specific condition, such as an element becoming clickable, up to a timeout. In Selenium it is written with WebDriverWait.

An explicit wait pauses a test until a particular condition is true, checking repeatedly and failing with a timeout if the condition never holds. It is “explicit” because you write it at the exact point where the test needs to wait and you say what to wait for. In Selenium 4 that means WebDriverWait combined with a condition from ExpectedConditions or a lambda.

Example (Selenium 4, Java)

import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

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

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

wait.until(ExpectedConditions.textToBePresentInElementLocated(
    By.cssSelector("[role='status']"), "Saved"));

// Any condition can be a lambda that returns a non-null or true value
wait.until(d -> d.findElements(By.cssSelector(".result-row")).size() == 20);

WebDriverWait polls every 500 ms by default and ignores NotFoundException while it polls. For a different interval or extra ignored exceptions, use FluentWait (withTimeout, pollingEvery, ignoring).

How it differs from an implicit wait

An implicit wait is a single global setting that makes every findElement call poll until the element exists. It knows nothing about visibility, clickability or text. An explicit wait targets one condition at one point in the test, so it can wait for exactly the state you need, such as a spinner disappearing or a button becoming enabled.

Selenium’s documentation warns against mixing the two, because combined timeouts can produce unpredictable wait times. Most teams keep the implicit wait at zero and use explicit waits everywhere.

Common mistakes

  • Thread.sleep instead of a wait. A fixed sleep is either too short (flaky) or too long (slow), and usually both, depending on the machine.
  • Waiting for presence when you need visibility. presenceOfElementLocated passes as soon as the node is in the DOM, even if it is hidden.
  • Holding a WebElement across a re-render. Wait on a By locator so the element is found again after the DOM changes.
  • Creating a new wait with a huge timeout in every helper. Centralise one sensible default in your framework.

Type to search across SDETRole.

Full-text search by Pagefind · runs in your browser Open search page →