</>

Technology

Selenium

Difficulty

Intermediate

Interview Question

What are different types of waits available in Selenium WebDriver?

Selenium provides three types of waits: Implicit Wait, Explicit Wait, and Fluent Wait.

Answer

Selenium WebDriver provides 3 types of waits to handle synchronization between test code and the browser:

1. Implicit Wait Tells WebDriver to wait for a specified time before throwing NoSuchElementException.

Java
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));

Applied globally to all findElement() calls.

2. Explicit Wait (WebDriverWait) Waits for a specific condition before proceeding.

Java
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("result")));

Applied to specific elements. Most commonly used in frameworks.

3. Fluent Wait Advanced explicit wait with custom polling interval and exception ignore list.

Java
Wait<WebDriver> fluentWait = new FluentWait<>(driver)
    .withTimeout(Duration.ofSeconds(30))
    .pollingEvery(Duration.ofSeconds(2))
    .ignoring(NoSuchElementException.class);

Comparison:

ImplicitExplicitFluent
ScopeGlobalPer elementPer element
Custom conditionsNoYesYes
Custom pollingNoNoYes
Best usePrototypingProduction testsAJAX/dynamic apps

Avoid Thread.sleep() — hard pause that wastes time even when element is ready.

Follow AutomateQA

Related Topics