web automation of the three waiting

This holiday season some long, long to forget the need to learn, to find a job, well, in my endless day chasing drama, I do not feel guilty after listening to a small share Cheung big brother, I even taking a nap are awakened. Big brother told me the same class, manufacturers work, but also take the time to learn every day, the job did not fall, take a look at yourself, and then contrast of others, and finally understand that I can not get well-paid turned out to be a reason, did not talk much He said that since yesterday I entered the web automated learning, today order the next three standby mode, hereby make a note of it, then you can forget the follow-up review.

Wait divided into three types:

1. Wait (commonly known Shadeng) time.sleep (2)

This waiting time is set according to, silly wait, wait for use with the third

2. recessive wait implicitly_wait (30)

Placed at the beginning and start dialogue browser for the current page, the hidden waiting, the waiting time elapsed before throwing an exception

Role: 1 waiting elements are found, 2 wait for the command execution is complete.

3. Explicit waiting 

After all the conditions are clearly stated and wait condition exists, then subsequent code execution

Wait: webdriverwait conditions: expected_condition

Wait 20 seconds interval detecting condition is satisfied: The default is 0.5 seconds

Upper sections of the code, like to understand

 

 

from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC 

session # beginning with the browser
dr = webdriver.Chrome ()
# the current page, the recessive wait 30 seconds
dr.implicitly_wait (30)

dr.get ( 'HTTP: // the WWW. baidu.com ')
# action, click on the login link
dr.maximize_window () # maximize the window
the time.sleep (2)

# find elements, click on the login link action
loc = (By.XPATH,' // * [@ id = " U1 "] // A [@ name =" tj_login "] ')
dr.find_element (* LOC) .click ()
the time.sleep (. 3)

# xxx wait visible element
# 1. targeting expression elements
loc = (By. ID, 'TANGRAM__PSP_10__footerULoginBtn')
# 1.WebDriverWait (DR, 20,1), the first parameter passed to it the current session, the second parameter is the maximum time to wait, the third parameter is the polling time 1s, the default is 0.5 seconds. You can leave
# 2.until (EC.visibility_of_element_located (loc)) is executed until the element is visible, parameters: loc tuple is generally used to express the immutable tuples
WebDriverWait (dr, 20,1) .until (EC.visibility_of_element_located (LOC))

# find elements login account and do click operation
dr.find_element (* LOC) .click ()
the time.sleep (2)
# end the session
dr. quit ()

So do we need to wait? 
Before operating elements, on the safe side, we need to wait
 

 

Guess you like

Origin www.cnblogs.com/irene3235/p/12355150.html