Mixing Waits

Introduction

Selenium provides multiple synchronization mechanisms such as Implicit Wait, Explicit Wait, and Fluent Wait. While each wait type is useful on its own, mixing different wait types can lead to unexpected behavior, longer execution times, and difficult-to-debug automation scripts.

Many beginners configure an Implicit Wait globally and later use Explicit Wait for specific elements, assuming both waits will work independently. However, this combination can produce unpredictable delays.

In this tutorial, you’ll learn what Mixing Waits means, why it is generally discouraged, practical examples, real-world scenarios, common mistakes, and best practices.


What is Mixing Waits?

Mixing Waits refers to using more than one type of Selenium wait in the same automation script.

For example:

  • Using Implicit Wait together with Explicit Wait.

  • Using Implicit Wait together with Fluent Wait.

Although Selenium allows this, it is generally not recommended because it can cause unexpected wait times.


Why is Mixing Waits Discouraged?

Each wait type has its own behavior.

When Implicit Wait and Explicit Wait are used together:

  • Selenium first applies the Implicit Wait while locating the element.

  • Then the Explicit Wait starts waiting for its condition.

  • As a result, the total waiting time can become longer than expected.

For modern Selenium automation frameworks, Explicit Wait is usually preferred because it provides more predictable and condition-based synchronization.


Example

The following example demonstrates the recommended approach of avoiding mixed waits by disabling the Implicit Wait and using only Explicit Wait to synchronize with dynamically loaded content.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


# Topic: 24. Advanced Synchronization - Mixing Waits
# Practice site: https://the-internet.herokuapp.com/dynamic_loading/2
# Run: pytest -s 24_examples/test_05_mixing_waits.py
#
# Combining implicit and explicit waits can cause unpredictable timeouts.
# Best practice: use explicit waits and set implicit wait to 0.


def test_mixing_waits():
    driver = webdriver.Chrome()
    driver.implicitly_wait(0)

    try:
        driver.get("https://the-internet.herokuapp.com/dynamic_loading/2")
        driver.find_element(By.CSS_SELECTOR, "#start button").click()

        WebDriverWait(driver, 10).until(
            EC.visibility_of_element_located((By.CSS_SELECTOR, "#finish h4"))
        )

        assert driver.find_element(
            By.CSS_SELECTOR,
            "#finish h4"
        ).is_displayed()

    finally:
        driver.quit()

Output

The dynamically loaded content
became visible successfully.

Explicit Wait handled the
synchronization without mixing
multiple wait strategies.

Understanding the Code

Disable Implicit Wait

driver.implicitly_wait(0)

Setting the Implicit Wait to 0 disables global waiting for element lookups.

This ensures that:

  • Only Explicit Wait handles synchronization.

  • Waiting behavior remains predictable.

  • Test execution becomes easier to understand and debug.

This is considered one of the best practices when using Explicit Wait extensively throughout an automation framework.


Open the Practice Website

driver.get(
    "https://the-internet.herokuapp.com/dynamic_loading/2"
)

Opens Selenium’s Dynamic Loading practice page.

The content displayed on this page loads asynchronously after clicking the Start button, making it ideal for demonstrating synchronization concepts.


Click the Start Button

driver.find_element(
    By.CSS_SELECTOR,
    "#start button"
).click()

Clicking the Start button begins the dynamic loading process.

The Hello World! message is not immediately available, so Selenium must wait until it becomes visible before continuing.


Create the Explicit Wait

WebDriverWait(driver, 10)

Creates an Explicit Wait with:

  • Maximum timeout → 10 seconds

  • Condition-based synchronization

  • Predictable waiting behavior

Selenium continuously checks whether the specified condition has been satisfied.


Wait Until the Element Becomes Visible

WebDriverWait(driver, 10).until(
    EC.visibility_of_element_located(
        (By.CSS_SELECTOR, "#finish h4")
    )
)

Selenium repeatedly checks whether the dynamically loaded element:

#finish h4

has become visible.

If the element appears before the timeout expires:

  • Selenium immediately proceeds with execution.

Otherwise:

  • A TimeoutException is raised.


Verify the Result

assert driver.find_element(
    By.CSS_SELECTOR,
    "#finish h4"
).is_displayed()

Verifies that:

  • The element became visible successfully.

  • Explicit Wait synchronized correctly with the webpage.

  • The test passed without requiring an Implicit Wait.


How Mixing Waits Works

The following diagram illustrates the process.

          Start Element Search
                    │
                    ▼
           Is Implicit Wait Enabled?
                 │          │
                Yes         No
                 │           │
                 ▼           ▼
         Apply Implicit Wait   Continue
                 │               │
                 ▼               ▼
          Explicit Wait Starts
                    │
                    ▼
             Check Condition
                    │
                    ▼
           Condition Satisfied?
                │          │
               Yes         No
                │           │
                ▼           ▼
          Continue      Keep Waiting
                             │
                     Timeout Reached?
                        │         │
                       No        Yes
                        │          │
                        ▼          ▼
                 Continue Waiting
                      Throw TimeoutException

Practical Example

Suppose an e-commerce website displays the Checkout button only after several API requests have completed.

If both Implicit Wait and Explicit Wait are configured, Selenium may spend additional time applying multiple waiting strategies before reporting a failure.

Using only Explicit Wait provides:

  • Faster execution.

  • Better synchronization.

  • More predictable timeout behavior.


Automation Testing Example

Consider an online banking application.

The automation framework configures:

  • Implicit Wait = Disabled

  • Explicit Wait = 15 seconds

After clicking the Login button:

  • Credentials are validated.

  • Dashboard data loads dynamically.

  • Transfer Funds becomes visible.

Using Explicit Wait alone allows Selenium to continue immediately when the required condition is satisfied without introducing unnecessary delays.


Real-World Example

Mixing waits can affect automation in:

  • Banking applications

  • E-commerce websites

  • CRM systems

  • Healthcare portals

  • Enterprise web applications

Large automation frameworks typically avoid mixing wait types to maintain predictable execution behavior.


Problems Caused by Mixing Waits

  • Longer execution times.

  • Unpredictable waiting behavior.

  • Difficult debugging.

  • Reduced automation performance.

  • Increased maintenance effort.


Common Mistakes Beginners Make

Configuring Both Implicit and Explicit Waits

Many beginners believe using multiple waits provides better synchronization.

In reality, it often:

  • Increases waiting time.

  • Makes failures difficult to debug.

  • Produces less predictable automation behavior.


Using Large Timeout Values

For example:

driver.implicitly_wait(30)

wait = WebDriverWait(driver, 30)

Large timeout values can significantly slow down failed test cases.


Assuming Waits Work Independently

Implicit Wait affects every element search, including those performed inside Explicit Wait conditions.

This interaction is one of the primary reasons mixing waits is discouraged.


Best Practices

  • Prefer Explicit Wait for dynamic web applications.

  • Avoid combining Implicit Wait with Explicit Wait.

  • If using Explicit Wait throughout the project, disable Implicit Wait or keep it at a very small value.

  • Use reasonable timeout values (typically 5–15 seconds).

  • Use appropriate Expected Conditions instead of relying on multiple wait strategies.


Conclusion

Although Selenium allows multiple wait types to be used together, mixing Implicit Wait with Explicit Wait or Fluent Wait is generally discouraged. It can introduce unpredictable delays, slow down automation, and make debugging more difficult. For modern web applications, using Explicit Wait consistently provides better synchronization, improved performance, and more reliable automation scripts.


Frequently Asked Questions (FAQs)

Can I use Implicit Wait and Explicit Wait together?

Yes.

Selenium allows it, but it is generally not recommended because it can lead to longer and unpredictable wait times.


Why does mixing waits increase execution time?

Because Selenium applies the Implicit Wait during element searches before evaluating the Explicit Wait condition.


Which wait should I use in modern Selenium projects?

Explicit Wait is generally preferred because it waits for specific conditions and provides better control.


Can I mix Fluent Wait with Implicit Wait?

Technically yes, but it is also discouraged for the same reasons as mixing Implicit Wait and Explicit Wait.


What is the recommended synchronization strategy?

Use Explicit Wait with appropriate Expected Conditions and avoid mixing multiple wait types unless there is a very specific requirement.


Key Takeaways

  • Mixing waits means using multiple Selenium wait types in the same automation script.

  • Combining Implicit Wait with Explicit Wait is generally discouraged.

  • Mixing waits can increase execution time and create unpredictable behavior.

  • Explicit Wait is the preferred synchronization mechanism for dynamic web applications.

  • Use appropriate timeout values and Expected Conditions.

  • Consistent use of a single synchronization strategy leads to cleaner and more reliable automation scripts.