Waits and Handling

 

Implicit, Explicit, Fluent Waits

Learning Outcome

4

Reduce timing issues and flaky test cases.

3

Apply suitable wait techniques for dynamic web elements.

2

Differentiate between Implicit, Explicit, and Fluent waits in Selenium

1

Understand why synchronization is important in web automation testing.

5

Build reliable and stable automation scripts using proper wait strategies.

 

Recall

Waits and Handling

 

Even after you write a locator (like By.id, By.xpath), it doesn’t guarantee the element is ready to use.

A locator only tells Selenium how to find an element,But it does not ensure the element is loaded, visible, or clickable

Element exists in code but not yet loaded in DOM

Element is in DOM but not visible

Element is visible but not clickable yet (e.g., still loading or disabled)

This leads to an Exceptions like:

 

  • NoSuchElementException

  • ElementNotInteractableException

  • ElementClickInterceptedException

Think of a modern restaurant or airport system where everything is dynamic, not fixed timing

 

Scenario: Restaurant System

You tell the waiter:

“I want a pizza at Table 5”

 

Step 1: You place an order (Locator)

 This is like Selenium using a locator (finding the element in DOM).

 

Problem: Order is not ready immediately

Even though the order is accepted:

  • Dough is still being prepared

  • Oven is heating

  • Final plating is not done

If you try to eat immediately → failure (like Selenium error)

 

 Step 2: Waiting is required (Synchronization)

 

Now the system has 3 different waiting behaviors:

 

1. Implicit Wait = “General Kitchen Buffer Time”

 

  • Restaurant policy:
    Every order may take up to 10 minutes

     

✔ You don’t ask every time
✔ It applies to all orders automatically

 

But:

  • No control on specific dish

  • Just a general safety buffer

  • Global waiting rule for all elements

2. Explicit Wait = “Wait for THIS dish only”

 

You specifically ask:

Tell me when my pizza is ready and served

 

✔ You are waiting for a specific condition

  • Pizza is cooked

  • Pizza is served
     

Very precise and condition-based

  • Wait for specific element state (visible/clickable)

3.Fluent Wait = “Smart waiter checking repeatedly

Now imagine a smart waiter:

  • Checks kitchen every 2 minutes

  • Ignores minor delays or errors

  • Keeps checking until food is ready or timeout happens
     

✔ Fully customizable:

  • How often to check (polling)

  • What issues to ignore (exceptions)

  • Flexible wait with polling + exception handling

Why Wait in Selenium WebDriver?

 

Web applications are often dynamic elements that don’t load instantly.

Selenium, however, executes commands very fast, which can create timing issues.

 

  • Elements may take time due to AJAX, APIs, or slow networks.

  • Without waits, Selenium may throw exceptions like NoSuchElementException or ElementNotInteractableException.

Avoid errors

Handle dynamic loading

  •  Synchronization ensures consistent and accurate test execution

Ensure element readiness​

  • Waits make sure elements are visible, clickable, or present before interaction.

  • Tests that sometimes pass and sometimes fail are stabilized using proper waits.

Reduce flaky tests

Improve reliability

What is Selenium Wait?

 

A wait in Selenium WebDriver is a synchronization mechanism that delays the execution of automation scripts until a specified condition is met or a web element becomes available, visible, or interactable, ensuring reliable interaction with dynamically loaded web pages.

 

There are three main types of waits used to handle synchronization in Selenium:

 

Implicit Wait

Explicit Wait

Fluent Wait

 

Implicit Wait is a global synchronization mechanism in Selenium that tells the WebDriver to wait for a specified amount of time when trying to locate any web element before throwing a “NoSuchElementException”.

Applied once for the entire WebDriver session

How It Works

 

Works whenever Selenium tries to find an element

If element is not immediately available, Selenium keeps checking the DOM until:


Element is found
OR timeout expires

Syntax Example (Java)

 

driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));

 

Example

When Selenium executes:
 

driver.findElement(By.id("username"));

 

It does NOT fail immediately. Instead:

 

  1. Searches DOM

  2. If not found → waits a little

  3. Repeats searching

  4. Continues until timeout is reached

This process is called polling with global timeout behavior

 

Summary

4

3

2

They allow automation scripts to interact with page elements

1

WebElements represent HTML elements on a web page in Selenium.

5

Check element states: displayed, enabled, selected.

 

Perform actions: click, type, clear, submit.

1

WebElements represent HTML elements on a web page in Selenium.

2

They allow automation scripts to interact with page elements.

3

Selenium provides methods to perform actions like click and type.

4

It also helps retrieve information from elements.

5

WebElements enable verification of element states for testing.

 

Quiz

Which method is used to enter text into an input field?

A.type()

B.write()

C.sendKeys()

D.inputText()

 

Quiz-Answer

Which method is used to enter text into an input field?

A.type()

B.write()

D.inputText()

 

C.sendKeys()

Waits and Handling (Implicit, Explicit, Fluent Waits)

By Content ITV

Waits and Handling (Implicit, Explicit, Fluent Waits)

  • 8