</>

Technology

Selenium

Difficulty

Beginner

Interview Question

What are the types of waits available in Selenium WebDriver?

Selenium provides Implicit Wait, Explicit Wait (WebDriverWait), Fluent Wait, PageLoadTimeout, and Thread.sleep() as synchronization mechanisms.

Answer

Types of Waits in Selenium WebDriver

Waits are synchronization mechanisms that tell Selenium to pause before interacting with elements that may not yet be available in the DOM.

1. Implicit Wait Applied globally — WebDriver waits up to N seconds for any element before throwing NoSuchElementException.

Java
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
// Applies to ALL findElement() calls in this driver session
driver.get("https://example.com");
driver.findElement(By.id("element"));  // Waits up to 10s

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

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

// Wait until element is visible
WebElement element = wait.until(
    ExpectedConditions.visibilityOfElementLocated(By.id("myElement"))
);

// Wait until element is clickable
WebElement btn = wait.until(
    ExpectedConditions.elementToBeClickable(By.id("submitBtn"))
);

3. Fluent Wait Custom explicit wait with configurable polling interval and exceptions to ignore.

Java
Wait<WebDriver> fluentWait = new FluentWait<>(driver)
    .withTimeout(Duration.ofSeconds(30))
    .pollingEvery(Duration.ofMillis(500))  // Check every 500ms
    .ignoring(NoSuchElementException.class)
    .ignoring(StaleElementReferenceException.class);

WebElement element = fluentWait.until(
    driver -> driver.findElement(By.id("dynamicElement"))
);

4. PageLoadTimeout Maximum time to wait for a page to fully load.

Java
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(30));
driver.get("https://heavy-site.com");  // Fails if page doesn''t load in 30s

5. Thread.sleep() — Static Wait Hard pause — waits regardless of application state.

Java
Thread.sleep(3000);  // Waits exactly 3 seconds — avoid unless necessary

Comparison table:

Wait TypeScopeCondition-basedRecommended
ImplicitGlobal (all findElement)NoUse sparingly
Explicit (WebDriverWait)Specific elementYesBest choice
FluentWaitSpecific elementYes (custom)Complex cases
PageLoadTimeoutPage navigationNoGlobal setting
Thread.sleepFixed pauseNoRarely / debugging

Key list from source:

  • Implicit Waits
  • Explicit Waits
  • Fluent Waits
  • PageLoadTimeOut
  • Thread.sleep() — static wait

Follow AutomateQA

Related Topics