Selenium delay waiting for the three way: forced to wait: SLEEP () Wait implicit: implicitly_wait () shows the wait WebDriverWait ()
1. forced to wait: SLEEP (), method in time module; can only for the current single-step operation; disadvantages: not a good control script execution speed, and only for the purposes of partial step of the operation, if the need to add each step too much duplicate code appears and the sleep time if more than five seconds will answer browser link is broken;
from Time Import SLEEP SLEEP ( 2) # incoming waiting time
2. Wait implicit: implicitly_wait (): Implicit wait; webdriver drive method in the object; is a session for all operations, is equivalent to a global wait; defined once only statements, scripts will typically be applied in the design method setUp ;
from Selenium Import the webdriver # leader packet Driver = webdriver.Chrome () # Get Object Browser drive driver.implicitly_wait ( 20 is) # implicit waiting, incoming latency
3. Wait display, WebDriverWait (drive object, waiting time)
# Two kinds of ways WebDriverWait introduced from selenium.webdriver.support.wait Import WebDriverWait # leader packet from selenium.webdriver.support.ui Import WebDriverWait # leader packet
from selenium.webdriver.support Import expected_conditions AS EC from selenium.webdriver.common.by Import By # WebDriverWait need to pass the object is to drive the overall waiting time interval and refresh interval default 0.5 # Presence_of_element_located indicate whether there must be an element yuan in the form of an incoming group, the use of the method By positioning WebDriverWait (Driver, 30, 0.5) .until (EC.presence_of_element_located ((By.ID, ' kW ' )))