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.
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.
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.
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.
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.
Thread.sleep(3000); // Waits exactly 3 seconds — avoid unless necessary
Comparison table:
| Wait Type | Scope | Condition-based | Recommended |
|---|---|---|---|
| Implicit | Global (all findElement) | No | Use sparingly |
| Explicit (WebDriverWait) | Specific element | Yes | Best choice |
| FluentWait | Specific element | Yes (custom) | Complex cases |
| PageLoadTimeout | Page navigation | No | Global setting |
| Thread.sleep | Fixed pause | No | Rarely / debugging |
Key list from source:
- ✓Implicit Waits
- ✓Explicit Waits
- ✓Fluent Waits
- ✓PageLoadTimeOut
- ✓Thread.sleep() — static wait
