Why to Use Wait: Most of the web apps are using AJAX techniques, This makes page element is loaded to browser may load at different time intervals.Using waits, we can solve this issue as Wait provides the time interval and some conditions to locate element.
Hence we can avoid the ElementNotVisibleException exception.
Selenium Webdriver provides two types of waits:
An explicit wait makes WebDriver to wait for a certain condition to occur before proceeding further with executions. There convenience methods provided that help you write code that will wait only as long as required. Using WebDriverWait in combination with ExpectedCondition is one way this can be accomplished.
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
driver = webdriver.Firefox()
userElement = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.NAME, "userName")))
passElement = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.NAME, "password")))
submitElement = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.NAME, "login")))
Below is the Expected Conditions that are used when automating web browsers.
Its used to tell WebDriver to search the DOM for a certain amount of time to find an element or elements if they are not immediately available.
In the next blog, We will see the Page Object and other important topics in Python.
2 thoughts on “Using Wait with Selenium in Python.”
Thank’s for sharing your knowledge. It will help us to solving problems related to automation testing using selenium web Driver.
My Pleasure 🙂