Implicit wait in Selenium Explicit wait in Selenium, Fluent Wait in Selenium

Selenium Wait Commands

It is very important to understand Selenium wait commands if you are trying to work on selenium automation. 

Why? Let’s see…

In Selenium test automation, the test execution is a RACE between the loading page and automation code execution. The webpage has to load before the execution of the related automation script statement for a successful test run.

If this doesn’t happen, your automation code just breaks!

So, if you want to leverage your test automation 100%, you have to master the concepts of selenium wait commands i.e. Implicit wait in Selenium, Explicit wait in Selenium and Fluent wait in Selenium.

These wait types are there to  handle this synchronization issue in Selenium WebDriver. You can find the details and difference between each one of them below.

Implicit Wait in Selenium

//This is an example of implicit wait. This statement ensures that the execution waits for element to be visible for 30 seconds. 
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

This is how Implicit Wait in Selenium is used. It is written once and applicable throughout the same instance of webdriver during execution. The polling interval for finding the element is 500ms. If element is not located in specified wait time, after the timeout, it throws ElementNotVisibleException

Explicit Wait in Selenium

//Explicit Wait
WebDriverWait wait = new WebDriverWait(driver,30);

This is how Explicit Wait in Selenium is used. It waits for certain condition to be met (condition as configured in the wait statement) so that execution finds the next WebElement to interact. It uses predefined methods of ExpectedConditions. The condition is checked by polling the page every 500ms. if condition is not met till the end of timeout period (30 seconds in the above example), it throws TimeoutException exception

Fluent Wait in Selenium

//Fluent Wait

Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)

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

This is how Fluent wait in Selenium is used in automation script. It is a more detailed wait command which can be customized at very granular levels. Generally we don’t need such level of customization in our test automation.

In Fluent wait, we can configure Polling interval, exception to ignore as well as conditions specific to the WebElement.

In the above example: 

Timeout = 30 Seconds

Polling interval= 5 Seconds

Exception to ignore= NoSuchElementException

If element is not located, ElementNotVisibleException is thrown after timeout.

Thread.sleep in Selenium


Thread.sleep in Selenium is just a plain type of wait which if used, has to inserted before every WebElement operation. 

It is just a hard coded wait which doesn’t care if the element is loaded on the page during or at the end of the wait time. Execution just jumps to the next statement after completion of the defined wait time.

Follow Us


APACHE code java jenkins selenium uft vbscript

Latest Posts
Want us to add
more code ?