delay waiting for selenium in three ways

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
Use webdriverwait can be used only until Not until two methods; and Not until until afferent parameter may be anonymous function or lambda preset condition expected_conditions
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 ' )))
If unitl or not unitl the incoming positioning element method to find the corresponding object will be returned, if not found an exception will be thrown TimeoutException
EC preset condition judgment module has many types:
determining whether the current element is present presence_of_element_located
Presence_of_all_elements_located determines whether there is a set of elements
Determining whether or not the element values ​​are Text_to_be_present_in_element_value text information xx
Presence_of_all_elements_located determines whether there is a set of elements
 

Guess you like

Origin www.cnblogs.com/XhyTechnologyShare/p/11820338.html