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.
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
Applied globally to all findElement() calls.
2. Explicit Wait (WebDriverWait) Waits for a specific condition before proceeding.
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.
Wait<WebDriver> fluentWait = new FluentWait<>(driver)
.withTimeout(Duration.ofSeconds(30))
.pollingEvery(Duration.ofSeconds(2))
.ignoring(NoSuchElementException.class);
Comparison:
| Implicit | Explicit | Fluent | |
|---|---|---|---|
| Scope | Global | Per element | Per element |
| Custom conditions | No | Yes | Yes |
| Custom polling | No | No | Yes |
| Best use | Prototyping | Production tests | AJAX/dynamic apps |
Avoid
Thread.sleep()— hard pause that wastes time even when element is ready.
