1. Explicit wait
An explicit wait is a piece of code that you define to wait for a condition to occur before proceeding with subsequent code execution.
From selenium import Webdriver
From selenium.webdriver.common.by Import by
From Selenium.webdriver.support.ui import webdriverwait # available since 2.4.0
From Selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
Driver = Webdriver. Firefox ()
Driver.get ("http://somedomain/url_that_delays_loading")
Try
element = webdriverwait (driver, ten). Until (Ec.presence_of_element_located ((By.id, "mydynamicelement"))
Finally
Driver.quit ()
2, implicit wait, equivalent to set the global wait, when the element is positioned, set the time-out for all elements.
The implicit wait allows Webdriver to poll the DOM every other time for an element or element array, if the element or array is not immediately discovered.
The default setting is 0.
Once set, this implicit wait takes effect throughout the life cycle of the Webdriver object instance.
From selenium import Webdriver
Driver = Webdriver. Firefox ()
Driver.implicitly_wait (Ten) # seconds
Driver.get (http://www.xxx.com)
Mydynamicelement = driver.find_element_by_id ("ElementID")
3. Forced wait
Import time
Time.sleep (10)
Selenium Webdriver three ways to wait