Waits and Handling

Implicit, Explicit, Fluent Waits

Learning Outcome

5

Improve test stability and reliability using proper wait strategies

4

Use waits to synchronize tests with application behavior.

3

Differentiate between Implicit, Explicit, and Fluent waits

2

Learn the concept of waits in automation testing

1

Understand why tests fail when elements load slowly

Waits: Making Your Test Patient

By synchronizing test execution with the application's state, waits ensure elements are ready before interaction

Waits are commands that tell Selenium to pause until a condition is met

They prevent flaky tests and improve automation stability

What is Waits?

ImplicitWait: A GlobalWait Strategy

  • Applies globally to all elements
  • Lacks fine-grained control

Pros 

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

What It Is

Sets a default wait time for every element search in your test session

Syntax

  • Easy to implement
  • Requires minimal code changes

Con

ExplicitWait: PrecisionWaiting with Conditions

Find Element

Interact

Pause until specific condition is met

Locate the element using a selector

Perform the desired action

Wait for Condition

1

2

3

Common Conditions for ExplicitWaits

Purpose

Conditon

Use Case

Waits until element is visible and enabled

elementToBeClickable()

Submit buttons after form validation

Waits until element is rendered and has size

visibilityOfElementLocated()

Modal dialogs, tooltips

Waits for JavaScript alert to appear

alertIsPresent()

Confirmation dialogs

Waits for element to exist in DOM

visibilityOfElementLocated()

Hidden elements, upcoming content

Fluent Wait: Custom Polling and Exception Handling

Check for condition at regular intervals until satisfied

Poll Repeatedly

Define timeout duration, polling frequency, and exceptions to ignore

CreateWait Instance

Gracefully manage exceptions during polling cycles

Handle Exception

Wait wait = new FluentWait(driver)
.withTimeout(Duration.ofSeconds(20))
.pollingEvery(Duration.ofSeconds(2))
.ignoring(NoSuchElementException.class);

Choosing the Right Wait for the Right Scenario

ImplicitWait

  • Simple, consistent delays

FluentWait

  • Retry logic for flaky element

ExplicitWait

  • Specific conditions

Low control granularity

Avoid with many dynamic elements

Global scope

Highest control granularity

Ideal for inconsistent timing

Per-element scope

Per-element scope

Best for fine control

High control granularity

Waits in Real Automation Projects

Wait for login button to become clickable after credentials are entered

Poll a data table after form submission until results appear

Wait for modal to close before interacting with elements behind it

Login Button

ModalWindow

Dynamic Table

Wait Smarter, Test Better

Review Flaky Tests

  • Identify unstable tests in your suite

Improve Test Reliability

  • Enjoy more consistent test results

Apply RightWait Strategy

  • Choose appropriate wait technique

Summary

5

4

3

2

1

Modern web applications load elements dynamically, which can cause test failures

Waits help tests pause until elements are ready

Implicit wait sets a default wait time for all elements

Explicit wait waits for specific conditions before interaction

Fluent wait allows custom waiting with polling and exception handling

Quiz

Which wait applies a default wait time to all elements?

A. Explicit Wait

B. Fluent Wait

C. Implicit Wait

D. Static Wait

Quiz-Answer

Which wait applies a default wait time to all elements?

A. Explicit Wait

B. Fluent Wait

C. Implicit Wait

D. Static Wait

Implicit, Explicit, Fluent Waits

By Content ITV

Implicit, Explicit, Fluent Waits

  • 5