Explicit Wait and its advantages

Let us now try to apply explicit wait to the same scenario discussed above. The explicit wait is applicable to a specific element on the page based on certain conditions.

The explicit wait is applied with the help of the WebDriverWait class. The driver object and the wait time are passed as parameters to that class. Then we have to create an object of that class. We have to import from selenium.webdriver.support.wait import WebDriverWait package to access the methods of the WebDriverWait class in our code.

Next we shall apply until method on the wait object and pass expected_conditions along with the behavior of the element as arguments. We also have to import from selenium.webdriver.support import expected_conditions package in our code. After importing this package we will be exposed to all the expected conditions available within that package. The below image lists down some of the expected conditions available in Selenium.

Now for our scenario, where it is taking more time to get the promo code applied and to get the success message, we shall take the help of the expected condition present_of_element_located and pass the locator type and element locator value as parameters.


w = WebDriverWait(driver, 8)


It means that Selenium shall wait until the element present is located and the element is rendered in DOM. We are specifically targeting one element and waiting for that element having the css value span.promoInfo to be available in the page.

After the explicit wait time (eight seconds) has passed and the element is still not available, it shall give a timeout exception. However, if the element is available at the third second, it shall resume the execution immediately without waiting for the complete eight seconds. This is another advantage of explicit wait.

Code Implementation with Explicit Wait:

from selenium import webdriver

from selenium.webdriver.common.by import By

from selenium.webdriver.support import expected_conditions

from selenium.webdriver.support.wait import WebDriverWait

driver = webdriver.Chrome(executable_path="C:\\chromedriver.exe")

# implicit wait time applied



# identify element with css selector and input search criteria



# pause execution for four seconds


# to identify list of ADD TO CART buttons


# to iterate over list of buttons

for button in b:

# to click on each button


# identify element with css selector and click


# identify element with xpath and click

driver.find_element_by_xpath("//*[text()='PROCEED TO CHECKOUT']")


# identify element with class name and input promo code



# identify element with css selector and click


# explicit wait time applied with expected condition

w = WebDriverWait(driver, 8)



# identify element for successful apply of promo code and print in console



The output shows the Code Applied..! message printed in the console log.


Thus we have seen how to use explicit wait along with example. For more details, you can refer to the link:


In the next blog post, we shall deep dive into functional automation with Python.


You may also like

Groups attribute in TestNG 

Groups attribute in TestNG 
Leave a Reply

Your email address will not be published. Required fields are marked

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}