A pragmatic approach to QA and OPS

Implicit Waits and Explicit Waits

Implicit Waits

As we have learnt before, implicit waits are a method to make the test wait for the webpage’s components to load, so that they can be available during our tests. Selenium originally borrowed this idea from Watir. Now what does implicit wait does actually. Suppose we wrote a script like this


from selenium import webdriver
import unittest

class AlertHandle(unittest.TestCase):

   def setUp(self):


  def test_Alterbox(self):
      print("This is a test to show implicit wait")
  def tearDown(self):

if __name__=="__main__"

Now the implicitly_wait( ) method tells the script , more precisely, it tells the Webdriver to poll the DOM for a certain amount of time , here for 30 seconds, when trying to find an element or elements if they are not immediately available. Here by poll, we mean to check the DOM again and again.

Once defined, implicit wait will be defined for the whole life time of a Webdriver object instance, until it is changed. So once defined in a script, it will be active for the lifetime of a script, until modified. By default, the implicit wait time set is 0.

Also, implicit wait won’t allow you to set any predefined conditions to wait for any webelement to be present or as such. If you want such kinda flexibility, you need to take the help of explicit wait, which is why we are going to discuss this in next section.


Explicit Wait

Not in every situation you want a predefined wait to be available in tests and wait for that long duration, for the element to be present or be visible in the DOM. We want to define a  wait condition, so that we can be able to wait for only that specific web element to be present and then carry on with the script functioning. To achieve this Selenium webdriver API provides us with explicit waits.

Explicit waits are a good way to organize a test script and provide more flexibility, by allowing us to design out tests in a way, where we can wait for some predefined or custom conditions and then carry on with what we want.

Explicit waits are implemented using the WebDriverWait and expected_conditions class of the python/Java API.

Let see an suppose we have a JS alert on a webpage, and we want to see if that clicking on that button, which fires the alert , actually fires the alert on not. Now, we would want this test to wait to click on the button and then only wait for that amount of time when the alert is not present. Once the alert appears, we would just want to accept it and then go on and accept the alert.


import unittest
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions

class Explicit_waiting(unittest.TestCase):

   def setUp(self):

       #getting the browser navigation

   def test_BrowserNav(self):





   def tearDown(self):

if __name__="__main__":


Now, focus specifically on this line of code


Here, we are using the WebDriverWait to make the driver wait a maximum of 10 seconds, until, the alert shows up. If the alert doesn’t appear in that stipulated time, the Webdriver will throw an NoAlertPresentException

During the course of test execution, Webdriver calls the ExpectedCondition every 500 milliseconds, untill it returns successfully.


Expected Conditions :

These are some common conditions which are frequently encountered when automating web applications.

Selenium Python binding provides some convenience methods so you don’t have to code an expected_condition class yourself or create your own utility package for them.

  • title_is
  • title_contains
  • presence_of_element_located
  • visibility_of_element_located
  • visibility_of
  • presence_of_all_elements_located
  • text_to_be_present_in_element
  • text_to_be_present_in_element_value
  • frame_to_be_available_and_switch_to_it
  • invisibility_of_element_located
  • element_to_be_clickable

You can read about the whole list of the expected conditions in the official Selenium python documentation here.



6 thoughts on “Implicit Waits and Explicit Waits

  1. Hi ,

    I have tried all waits for page load but still i am unable to proceed the actions .Could you please help me from this .



      1. I am implementing automation script for web application .In this application every entry internally page getting refreshing (It’s waiting for DOM load ) . I have tried all waits which i know like :
        1. wait for page to load
        2.wait for element visible
        3.wait for element clickable
        4.wait for element present
        5.wait for element not visible
        6.implicit wait

        Still i am getting pass cases .when i am using time.sleep(2) ..it’s getting pass.


        Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: