Understand Different Types of Selenium Wait Commands

Master Selenium waits to handle dynamic elements and improve test reliability. Execute these tests on real browsers and devices with BrowserStack for accurate, consistent results.

Ways to Install Appium- Rohit
Home Guide Selenium Wait Commands in 2026

Selenium Wait Commands in 2026

Most testers assume that if a Selenium script uses the right locators and commands, their tests will pass consistently. I used to think the same, believing that writing scripts, targeting elements, and running them locally was enough to catch most issues.

But even with correct logic, my tests often fail unpredictably. Elements may appear late, be temporarily invisible, or exist in the DOM but not yet be interactable. Even one second of difference can break a test and waste hours of debugging code that isn’t actually broken.

You can resolve this by using the right Selenium Wait Command, and make tests respond exactly when an element or condition is ready.

In this article, I will explain implicit, explicit, and fluent waits, show when to use each, and help you handle dynamic pages and reduce flakiness in 2026.

What are Wait commands in Selenium?

In Selenium, wait commands are used to synchronize the execution of test scripts with the state of the web application. Wait Commands help ensure that the script waits for certain conditions to be met before proceeding, which is crucial for dynamic web pages where elements may take time to load.

This helps in avoiding exceptions that occur when the elements to be tested are not loaded. Wait commands are essential when it comes to executing Selenium tests. They help to observe and troubleshoot issues that may occur due to variation in time lag.

Wait Commands Behaving Differently?

Different browsers interpret waits differently. Validate waits under real conditions to prevent hidden failures.

While running Selenium tests, it is common for testers to get the message “Element Not Visible Exception“. This appears when a particular web element with which WebDriver has to interact, is delayed in its loading. To prevent this Exception, Selenium Wait Commands must be used.

In automation testing, Selenium Webdriver wait commands direct test execution to pause for a certain length of time before moving onto the next step. This enables WebDriver to check if one or more web elements are present/visible/enriched/clickable, etc.

Why do you need Selenium Webdriver Wait commands in 2026?

When a web page loads on a browser, various web elements (buttons, links, images) that someone wants to interact with may load at various intervals.

In automated Selenium testing, this causes some trouble when identifying certain elements. If an element is not located, then the “ElementNotVisibleException” appears. Selenium Wait commands help resolve this issue.

Wait commands are essential for ensuring the stability, reliability, and effectiveness of automated tests in Selenium, especially when dealing with dynamic web applications.

You need Selenium Webdriver Wait Commands for the following reasons:

  • Dynamic Content Handling: Many web applications load elements dynamically, meaning elements may not be immediately available when the script tries to interact with them. Wait commands help ensure that the script only proceeds once the necessary elements are present.
  • Reducing Flakiness: Without appropriate waits, tests may fail sporadically due to timing issues, leading to unreliable test results. Wait commands help stabilize tests by allowing the application time to load completely.
  • Improved Test Reliability: By waiting for specific conditions (e.g., visibility of elements, completion of actions), tests become more robust and less prone to errors caused by slow loading times or unexpected delays.
  • Error Handling: Using wait commands can prevent exceptions like NoSuchElementException or ElementNotInteractableException by ensuring that the script only interacts with elements that are ready.
  • Performance Optimization: Implicit waits can help reduce the overall runtime of tests by minimizing unnecessary polling. Explicit waits focus on specific conditions, which can lead to faster and more efficient test execution.
  • Realistic User Simulation: Wait commands mimic real user behavior more closely, as users naturally wait for elements to load or respond. This leads to more accurate testing of the application’s performance and user experience.

Read More about the Common Exceptions in Selenium.

Selenium WebDriver provides three commands to implement waits in tests.

  1. Implicit Wait
  2. Explicit Wait
  3. Fluent Wait

Wait Commands in Selenium Horizondal

Implicit Wait in Selenium

Implicit wait makes WebDriver to wait for a specified amount of time when trying to locate an element before throwing a NoSuchElementException. When implicit wait is set, the WebDriver will wait for a defined period, allowing for elements to load dynamically.

Implicit Wait setting is a Global setting and applies to all elements in the script, and it remains in effect for the duration of the WebDriver instance.

Once the command is run, Implicit Wait remains for the entire duration for which the browser is open. It’s default setting is 0, and the specific wait time needs to be set by the following protocol.

To add implicit waits in test scripts, import the following package.

import java.util.concurrent.TimeUnit;

Implicit Wait Syntax

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

Add the above code into the test script. It sets an implicit wait after the instantiation of WebDriver instance variable.

Advantages of Implicit Wait

Implicit wait creates a default polling behaviour for every element lookup. Instead of failing instantly when an element is not found, Selenium keeps checking the DOM at regular intervals until the timeout is reached.

Below are the key advantages of implicit wait:

  • Automatic safety net: Every findElement call benefits from the same retry logic, so even if multiple elements load late, there is no need to add waits individually. The test is naturally more forgiving without extra code.
  • Consistent across the suite: Because the timeout applies globally, Selenium behaves the same way for every element search. Teams do not accidentally wait 2 seconds in one place and 10 in another, which avoids uneven test timing.
  • Zero cognitive overhead: Test authors do not need to think about which condition to wait for. If the only requirement is “element must exist in the DOM at some point”, implicit wait handles it silently.
  • Good for non-interactive elements: Static labels, hidden fields, small images, and supporting elements often do not need visibility or clickability conditions. They simply need to be present. Implicit wait avoids over-engineering these cases.
  • Prevents aggressive failures: Without implicit wait, Selenium throws NoSuchElementException immediately. Even a 200–300 ms delay in rendering would break tests frequently. Implicit wait absorbs these micro-delays and keeps the run stable.
  • Ideal for simple synchronization: Some applications use minimal JavaScript and predictable server responses. In these cases, explicit conditions are unnecessary, and a single implicit timeout keeps the suite stable without extra complexity.

When to Use Implicit Wait

Implicit wait removes the need to sprinkle short sleeps everywhere and gives a consistent baseline for element lookup.

It works well in the following cases:

  • Stable UI with minor delays: Elements exist predictably but render slightly later than expected.
  • Multiple dependent elements: All findElement calls benefit without writing explicit waits for each field.
  • Smoke suites and happy paths: Simple flows where readability and clean code matter more than granular control.

Example of Implicit Wait Command

In the following example, we use Implicit Wait in Selenium to set a global wait time for the WebDriver. The driver will automatically wait up to 30 seconds for elements to appear before throwing an exception, helping handle elements that load slowly.

Package waitExample;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class WaitTest {

private WebDriver driver;
private String baseUrl;
private WebElement element;

@BeforeMethod
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://www.google.com";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

@Test
public void testUntitled() throws Exception {
driver.get(baseUrl);
element = driver.findElement(By.id("lst-ib"));
element.sendKeys("Selenium WebDriver Interview questions");
element.sendKeys(Keys.RETURN);
List<WebElement> list = driver.findElements(By.className("_Rm"));
System.out.println(list.size());

}

@AfterMethod
public void tearDown() throws Exception {
driver.quit();
}
}

However, implicit wait increases test script execution time. It makes each command wait for the defined time before resuming test execution. If the application responds normally, the implicit wait can slow down the execution of test scripts.

Explicit Wait in Selenium

Explicit wait in Selenium is a synchronization mechanism that allows the WebDriver to wait for a specific condition to occur before proceeding with the next step in the code. Unlike Implicit waits, which apply globally, explicit waits are applied only to specific elements or conditions, making them more flexible and precise.

Setting Explicit Wait is important in cases where there are certain elements that naturally take more time to load. If one sets an implicit wait command, then the browser will wait for the same time frame before loading every web element. This causes an unnecessary delay in executing the test script.

Explicit wait is more intelligent, but can only be applied for specified elements. However, it is an improvement on implicit wait since it allows the program to pause for dynamically loaded Ajax elements.

In order to declare explicit wait, one has to use ExpectedConditions.

Types of Explicit Wait Conditions:

  1. alertIsPresent()
  2. elementSelectionStateToBe()
  3. elementToBeClickable()
  4. elementToBeSelected()
  5. frameToBeAvaliableAndSwitchToIt()
  6. invisibilityOfTheElementLocated()
  7. invisibilityOfElementWithText()
  8. presenceOfAllElementsLocatedBy()
  9. presenceOfElementLocated()
  10. textToBePresentInElement()
  11. textToBePresentInElementLocated()
  12. textToBePresentInElementValue()
  13. titleIs()
  14. titleContains()
  15. visibilityOf()
  16. visibilityOfAllElements()
  17. visibilityOfAllElementsLocatedBy()
  18. visibilityOfElementLocated()

To use Explicit Wait in test scripts, import the following packages into the script.

import org.openqa.selenium.support.ui.ExpectedConditions
import org.openqa.selenium.support.ui.WebDriverWait

Then, Initialize A Wait Object using WebDriverWait Class.

Explicit Wait Syntax

WebDriverWait wait = new WebDriverWait(driver,30);

Here, the reference variable is named <wait> for the <WebDriverWait> class. It is instantiated using the WebDriver instance. The maximum wait time must be set for the execution to layoff. Note that the wait time is measured in seconds.

Advantages of Explicit Wait

Explicit wait allows Selenium tests to pause dynamically until a specific condition is met, rather than waiting blindly. Key advantages of explicit wait include:

  • Precise control over conditions: Wait only for element visibility, clickability, text presence, or custom conditions, rather than waiting arbitrarily.
  • Improves test reliability: Reduces random failures caused by slow-loading elements, asynchronous updates, or delayed rendering.
  • Flexible timeout per scenario: Each wait can have a different duration depending on the element or step, allowing optimization of test speed and stability.
  • Supports complex dynamic pages: Handles AJAX content, JavaScript-driven changes, and elements that appear or disappear after user actions.
  • Avoids unnecessary delays: Unlike fixed sleeps, explicit wait continues as soon as the condition is met, speeding up execution.
  • Better debugging and logging: Explicit waits can throw descriptive exceptions when a condition fails, making it easier to identify why a test didn’t pass.
  • Combines well with fluent wait: Provides a foundation to add polling frequency, ignored exceptions, and custom conditions for highly dynamic or flaky elements.

When to Use Explicit Wait

Explicit wait is most effective when you need precise control over element readiness rather than a blanket delay. Use it in situations like the following:

  • Elements load asynchronously: Use when content appears after AJAX calls, animations, or delayed JavaScript rendering.
  • Specific element conditions: Wait for visibility, clickability, text presence, or custom conditions before interacting.
  • Dynamic pages with unpredictable load times: Ideal for SPAs or pages where elements appear at different times across runs.
  • Critical actions with high failure impact: Ensure important clicks, form submissions, or validations execute only when the element is ready.
  • Short-lived elements: Handle pop-ups, alerts, or temporary messages that may appear briefly.
  • Combination with polling logic: Useful when you need custom retry intervals or want to ignore certain exceptions during the wait.

Wait Commands Behaving Differently?

Different browsers interpret waits differently. Validate waits under real conditions to prevent hidden failures.

Example of Explicit Wait Command

In the following example, the test script is for logging into “gmail.com” with a username and password. After a successful login, the code waits for the “compose” button to be available on the home page. Here, you have to wait until the element is visible (Compose Button in this case) using the explicit wait command. Finally, it clicks on the button.

package waitExample;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class ExpectedConditionExample {
// created reference variable for WebDriver
WebDriver driver;

@BeforeMethod
public void setup() throws InterruptedException {

// initializing driver variable using FirefoxDriver
driver=new FirefoxDriver();
// launching gmail.com on the browser
driver.get("https://gmail.com");
// maximized the browser window
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}

@Test
public void test() throws InterruptedException {
// saving the GUI element reference into a "element" variable of WebElement type
WebElement element = driver.findElement(By.id("Email"));
// entering username
element.sendKeys("dummy@gmail.com");
element.sendKeys(Keys.RETURN);
// entering password
driver.findElement(By.id("Passwd")).sendKeys("password");
// clicking signin button
driver.findElement(By.id("signIn")).click();
// explicit wait - to wait for the compose button to be click-able
WebDriverWait wait = new WebDriverWait(driver,30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[contains(text(),'COMPOSE')]")));
// click on the compose button as soon as the "compose" button is visible
driver.findElement(By.xpath("//div[contains(text(),'COMPOSE')]")).click();
}

@AfterMethod
public void teardown() {
// closes all the browser windows opened by web driver
driver.quit();
}

}

The above code instructs Selenium WebDriver to wait for 30 seconds before throwing a TimeoutException. If it finds the element before 30 seconds, then it will return immediately. After that, it will click on the “Compose” button. In this case, the program will not wait for the entire 30 seconds, thus saving time and executing the script faster.

Fluent Wait in Selenium

Fluent Wait in Selenium marks the maximum amount of time for Selenium WebDriver to wait for a certain condition (web element) becomes visible. It also defines how frequently WebDriver will check if the condition appears before throwing the “ElementNotVisibleException”.

To put it simply, Fluent Wait looks for a web element repeatedly at regular intervals until timeout happens or until the object is found.

Fluent Wait commands are most useful when interacting with web elements that can take longer durations to load. This is something that often occurs in Ajax applications.

While using Fluent Wait, it is possible to set a default polling period as needed. The user can configure the wait to ignore any exceptions during the polling period.

Fluent waits are also sometimes called smart waits because they don’t wait out the entire duration defined in the code. Instead, the test continues to execute as soon as the element is detected – as soon as the condition specified in .until(YourCondition) method becomes true.

Fluent Wait Syntax

Wait wait = new FluentWait(WebDriver reference)
.withTimeout(timeout, SECONDS)
.pollingEvery(timeout, SECONDS)
.ignoring(Exception.class);

WebElement foo=wait.until(new Function<WebDriver, WebElement>() {
public WebElement applyy(WebDriver driver) {
return driver.findElement(By.id("foo"));
}
});

Advantages of Fluent Wait

Fluent wait extends explicit wait by providing custom polling intervals and the ability to ignore specific exceptions during the wait period. Key advantages of fluent wait include:

  • Custom polling intervals: Unlike implicit or standard explicit waits, you can define how often Selenium checks for the condition, reducing unnecessary delays.
  • Handles transient exceptions: Can ignore exceptions like NoSuchElementException or StaleElementReferenceException during the wait, improving test stability.
  • Flexible timeout per element: Each wait can have a different total duration and polling frequency, allowing optimization for specific elements.
  • Supports complex conditions: Fluent wait allows combining multiple checks or using custom functions to define readiness.
  • Ideal for highly dynamic pages: Works well with SPAs or pages with elements that load unpredictably or intermittently.
  • Reduces test flakiness: Ensures interactions only happen when the element is reliably present and ready, even in unstable environments.
  • Integrates with explicit wait logic: Can be used wherever explicit wait is used, providing a more granular control when needed.

When to Use Fluent Wait

Fluent wait builds on explicit wait by adding custom polling intervals and the ability to ignore specific exceptions while waiting. It is ideal for elements that appear intermittently or under unpredictable conditions. Use it in situations like the following:

  • Highly dynamic elements: Elements that appear and disappear rapidly or at irregular intervals on the page.
  • Custom polling requirements: When you want to check the condition repeatedly at shorter or longer intervals than the default.
  • Ignoring transient exceptions: Useful for handling NoSuchElementException or StaleElementReferenceException while waiting.
  • Long-running asynchronous operations: Wait for elements or conditions that take variable time to become ready without blocking other test steps unnecessarily.
  • Complex custom conditions: Ideal when you need to wait for multiple conditions or write a lambda function to define readiness.
  • Flaky UI interactions: Ensures stable interactions in environments with inconsistent network, rendering, or backend delays.

Example of Fluent Wait Command

In this example, we use Fluent Wait in Selenium to wait for an alert to appear. It sets a maximum timeout, defines polling intervals, and ignores specified exceptions, allowing tests to handle elements that appear unpredictably.

//Declare and initialise a fluent wait
FluentWait wait = new FluentWait(driver);
//Specify the timout of the wait
wait.withTimeout(5000, TimeUnit.MILLISECONDS);
//Sepcify polling time
wait.pollingEvery(250, TimeUnit.MILLISECONDS);
//Specify what exceptions to ignore
wait.ignoring(NoSuchElementException.class)

//This is how we specify the condition to wait on.
//This is what we will explore more in this chapter
wait.until(ExpectedConditions.alertIsPresent());

This command operates with two primary parameters: timeout value and polling frequency. The above code defines the time out value as 5 seconds and polling frequency as 0.25 seconds. It directs WebDriver to wait for no more than 5 seconds to verify a specific condition. If the condition occurs during those 5 seconds, it will execute the next step in the test script. If not, it will return “ElementNotVisibleException”.

Run Selenium Tests on Real Devices

A few other associated commands are:

  • PageLoadTimeout Command

This command establishes the time WebDriver must wait for a page to completely load before triggering an error. In case the timeout set is negative, the page load time can be indefinite.

Syntax:

driver.manage().timeouts().pageLoadTimeout(100, SECONDS);
  • SetScriptTimeout Command

This command establishes the time WebDriver will wait for an asynchronous script to finish executing before triggering an error. Like the previous command, the script will run indefinitely if the timeout is set to a negative value.

Syntax:

driver.manage().timeouts().setScriptTimeout(100,SECONDS);
  • Sleep Command

Thread Sleep command is rarely used because it is quite ineffective. It causes WebDriver to wait for a specific time (and does not let it run faster even if the specified condition is met). In fact, Selenium wait commands are considered the smarter, more effective alternative to the Sleep command.

Syntax:

thread.sleep(1000);

Difference between Implicit and Explicit Wait Commands in Selenium

The major difference between implicit and explicit wait is that: Implicit wait is applicable to all the elements in the test script, Explicit wait applies to the specific element only.

Here is the detailed illustration of Implicit vs Explicit Wait in Selenium below to help you understand when to use which.

Implicit Wait in SeleniumExplicit Wait in Selenium
Applies to all elements in a test script.Applies only to specific elements as intended by the user.
No need to specify “ExpectedConditions” on the element to be locatedMust always specify “ExpectedConditions” on the element to be located
Most effective when used in a test case in which the elements are located with the time frame specified in implicit waitMost effective when used when the elements are taking a long time to load. Also useful for verifying property of the element, such as visibilityOfElementLocated, elementToBeClickable, elementToBeSelected

Why Use BrowserStack for Selenium Wait‑Command Testing

Testing with implicit, explicit, or fluent waits comes with common challenges. Tests may pass locally but fail on other browsers or devices. Waits can time out for unclear reasons because elements may appear late, be temporarily invisible, or behave differently on certain platforms or under different network conditions.

Platforms like BrowserStack address these issues by providing real browsers and devices for testing. Each test run includes screenshots, video recordings, and detailed logs, making it easy to debug why a wait failed.

Here are core features of BrowserStack that helps test Selenium scripts:

  • Selenium Grid on Cloud: Access a cloud-hosted Selenium Grid to run tests on hundreds of browsers and devices without maintaining infrastructure.
  • Parallel Testing: Execute multiple tests simultaneously to save time and speed up validation of wait commands across different environments.
  • Reporting & Analytics: Get detailed logs, screenshots, and test reports to debug wait failures and monitor test performance.
  • Real Device Features: Test on actual mobile and desktop devices to capture real-world behavior for elements and waits.
  • Web Performance Testing: Measure page load, element render times, and responsiveness to ensure waits handle real-world performance variations.

Wait Commands Behaving Differently?

Different browsers interpret waits differently. Validate waits under real conditions to prevent hidden failures.

Conclusion

Implicit, explicit, and fluent waits each have their advantages and best-use scenarios, and selecting the right wait ensures tests interact with elements only when they are ready. Proper use of waits reduces flakiness, improves test stability, and helps teams maintain confidence in their automation suites.

Platforms like BrowserStack provide real browsers and devices, parallel execution, and detailed reporting to validate waits under real-world conditions. Leveraging such platforms ensures Selenium tests are not only well-written but also reliable, consistent, and scalable across environments.

Run Selenium Tests on Cloud

Tags
Automation Testing Selenium Selenium Webdriver

FAQs

Selenium waits prevent tests from failing due to elements not being ready. By pausing execution until conditions are met, they improve reliability, handle dynamic content, and reduce flaky test results across varying page load times.

Yes, explicit and fluent waits are ideal for AJAX content. They allow the test to wait for specific elements or conditions triggered by asynchronous calls, ensuring that dynamically loaded content is fully available before interacting with it.

Explicit wait pauses until a condition is met, checking at fixed intervals. Fluent wait offers more control by specifying polling frequency and ignoring exceptions, making it better suited for highly dynamic or unpredictable elements.

Yes, implicit wait applies globally and can slow tests if overused, because it makes WebDriver poll for elements repeatedly until the timeout. Proper use with reasonable durations prevents unnecessary delays and improves stability.

Common mistakes include using unnecessarily long timeouts, waiting for incorrect conditions, mixing implicit and explicit waits, and not handling exceptions properly, which can lead to slower or flaky tests and unpredictable results.

Fluent wait can be faster than implicit wait because it checks conditions at defined intervals and ignores exceptions, reducing idle time. Explicit wait is also efficient when correctly targeted, whereas implicit wait can introduce unnecessary delays.

Yes, if used with long timeouts or on elements that appear quickly, explicit wait can unnecessarily pause execution. Optimizing conditions and timeout values ensures tests remain efficient while remaining reliable.

15% of Selenium Tests Fail Due to Wrong Waits
Validate your waits on real browsers & devices to catch failures & improve stability across environments.

Get answers on our Discord Community

Join our Discord community to connect with others! Get your questions answered and stay informed.

Join Discord Community
Discord