DZone
Web Dev Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Web Dev Zone > Wait Types: An Important Aspect in the Selenium Automation Process

Wait Types: An Important Aspect in the Selenium Automation Process

In this quick tutorial, we'll go over Implicit, Explicit, and Fluent wait types, and how to go about using them in an automated Selenium environment.

Soumyajit Basu user avatar by
Soumyajit Basu
CORE ·
Jun. 10, 17 · Web Dev Zone · Tutorial
Like (3)
Save
Tweet
17.83K Views

Join the DZone community and get the full member experience.

Join For Free

In this blog, I would be discussing the important aspects of different wait types in Selenium's automation process. I have seen that there is a huge confusion in understanding different wait types and its significance when it comes to Selenium automation. So this blog would exclusively explain what the different wait types are.

There are basically three wait types in Selenium automation:

  1. Implicit Wait Type
  2. Explicit Wait Type
  3. Fluent Wait Type

Implicit Wait Type

Selenium WebDriver has borrowed the idea of ‘Implicit Wait’ type from Watir. This basically tells Selenium to wait for a certain amount of time before throwing an exception if cannot find the element of the page. We should note that the implicit wait will be in place for the entire time the browser is open. This means that any search for elements on the page by the webdriver should use the time designated for the implicit wait. If we do not provide Selenium with this wait, then Selenium would start throwing ElementNotFound exceptions because the time taken for Selenium to interact with the corresponding element in the browser was not given. This is applicable for all the web elements in the browser for the entire browser session. For example:

from selenium import webdriver

class BrowserInteractions():
    def test(self):
        driver = webdriver.Firefox()
        driver.get('https://google.com')
        driver.implicitly_wait(10)

Explicit Wait Type

Explicit wait is more extendable, in so far as you can set it up to wait for any specific condition. Usually, we use theExpectedCondition object to specify the condition to provide the corresponding explicit wait. For example:

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

class BrowserInteractions():
    def test(self):
        driver = webdriver.Chrome()
        driver.get('http://www.quora.com/Kevin-Rose')
        element = WebDriverWait(driver, 2).until(
            EC.presence_of_element_located((By.
            PARTIAL_LINK_TEXT, "Followers")))
        element.click()

Fluent Wait Type

Fluent wait is a part of the Explicit Wait type. Fluent wait instances define the maximum amount of time to wait for a condition, as well the frequency with which to check the condition. For example:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import *
import time

class ExplicitWait():
    def test(self):
        baseURL = "http://www.cleartrip.com/"
        bin_path = "/usr/local/bin/chromedriver"
        driver = webdriver.Chrome(executable_path=bin_path)
        driver.get(baseURL)
        driver.implicitly_wait(.5)
        driver.maximize_window()
        input_from = driver.find_element(By.ID,"FromTag")
        input_from.send_keys("blr")
        input_to = driver.find_element(By.ID,"ToTag")
        input_to.send_keys("ccu")
        input_depart_date = driver.find_element(By.ID,"DepartDate")
        input_depart_date.send_keys("Sun, 4 Jun, 2017")
        input_depart_date.send_keys(Keys.ENTER)

        input_searchBtn = driver.find_element(By.ID,"SearchBtn")
        input_searchBtn.click()
        wait = WebDriverWait(driver, 10, poll_frequency=1,
               ignored_exceptions=[NoSuchElementException,
                                   ElementNotVisibleException,
                                   ElementNotSelectableException])
        element = wait.until(EC.
                  element_to_be_clickable((By.ID,"1_1_MULTI")))
        element.click()
        time.sleep(2)
        driver.quit()

ew = ExplicitWait()
ew.test()

This is a very important concept when we are performing automation using Selenium, and I hope I was able to clear the difference between the three wait types.

Aspect (computer programming)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Open Source Security Risks
  • OpenTelemetry in Action: Identifying Database Dependencies
  • A Smarter Redis
  • Java: Why Core-to-Core Latency Matters

Comments

Web Dev Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo