Q1 of 37 · Selenium
What are the different types of waits in Selenium?
Short answer
Short answer: Implicit waits set a global polling timeout for findElement; explicit waits poll for a specific condition; fluent waits add custom polling and ignored exceptions. Use explicit waits — implicit waits compound silently and are widely considered an anti-pattern.
Detail
Selenium ships three waiting mechanisms with very different ergonomics.
Implicit wait — driver.manage().timeouts().implicitlyWait(...). A global setting that tells the driver "if you can't find an element, keep polling for up to N seconds." It feels convenient but it's a trap: it interacts badly with explicit waits (timeouts can stack), it makes "element not found" failures take much longer, and it doesn't help with conditions that aren't "is the element present?". Most teams set it to zero and never use it.
Explicit wait — new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(...)). You pick the condition (visible, clickable, text matches, custom function), and Selenium polls until it's met or times out. This is the right tool for almost every case.
Fluent wait — a configurable Wait<T> where you set polling interval, timeout, and which exceptions to ignore (NoSuchElementException, StaleElementReferenceException). It's an explicit wait with finer-grained control — useful when you need to retry through transient stale-element errors.
The interview-worthy point: never use Thread.sleep in tests, and never combine implicit and explicit waits. Both lead to slow, flaky suites that nobody trusts.
// EXAMPLE
ExplicitWait.java
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.time.Duration;
public class CheckoutTest {
public void clickPayWhenReady(WebDriver driver) {
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
// Wait for the button to be clickable, not just present
WebElement payButton = wait.until(
ExpectedConditions.elementToBeClickable(By.cssSelector("[data-test=pay]"))
);
payButton.click();
// Wait for the success heading
wait.until(ExpectedConditions.textToBePresentInElementLocated(
By.tagName("h1"), "Order confirmed"
));
}
}