Python automated learning - positioning elements

Selenium the webdriver Import from 
Import Time 

Driver = webdriver.Chrome () 
driver.get ( "https://www.baidu.com/index.php?tn=25017023_6_pg&ssl_s=1&ssl_c=ssl1_16d7f66ac98") 
'' ' 
ID # positioning of the positioning element 
driver.find_element_by_id ( "kw"). send_keys ( " Huawei") 
driver.find_element_by_id ( "SU"). () the Click 
'' ' 
' '' 
class name of the positioning element positioned # 
driver.find_element_by_class_name ( "s_ipt"). send_keys ( "glory") 
driver.find_element_by_id ( "SU"). () the Click 
'' ' 
' '' 
Tag # positioning element of the positioning 
driver.find_element_by_tag_name ( "INPUT"). send_keys ( "Linux") 
Driver.find_element_by_id("su").click()
'''
''' 
# positioning element of the positioning link text
driver.find_element_by_link_text("新闻").click() 
the time.sleep (. 3) 
'' ' 

"" " 
Location of the partial link # positioning elements (like the fuzzy positioning) 
driver.find_element_by_partial_link_text (" Hao "). the Click () 
Time .sleep (. 3) 
"" " 
'' ' 
# XPath location of the positioning element positioned absolute path 
driver.find_element_by_xpath (' // * [@ id =" kw "] '). send_keys (" National Festival ") 
driver.find_element_by_xpath ( '// * [@ ID = "SU"]'). the Click () 
(. 3) the time.sleep 
'' ' 
' '' 
the XPath Location attribute positioning element of the positioning element # 
driver.find_element_by_xpath ( '// input [@id = "kw"] '). send_keys ( " millet official website") 
driver.find_element_by_xpath ('INPUT // [@ ID = "SU"] '). the Click () 
(. 3) the time.sleep 
' '' 
'' ' 
the XPath elements and attributes of the binding level positioning element positioned #
driver.find_element_by_xpath ( '// span [@ class = "bg s_ipt_wr quickdelete-wrap"] / input'). send_keys ( " pants") 
(2) the time.sleep 
'' ' 
' '' 
the XPath Location of the logical operation element # website positioning 
driver.find_element_by_xpath ( "// * [@ id = 'kw' and @ class = 's_ipt']"). send_keys ( " pants") 
the time.sleep (2) 
'' ' 
' '' 
# of positioning elements the method of the contains XPath 
driver.find_element_by_xpath ( "// span [contains ( @ class, 's_ipt_wr')] / input"). send_keys ( " pants") 
(2) the time.sleep 
'' ' 
' '' 
# of positioning elements XPath text () and contains in conjunction to achieve the effect of the link text positioning 
driver.find_element_by_xpath ( "// a [contains ( text (), 'hao')]").the Click () 
the time.sleep (2) 
'' ' 
' '' 
#CSS positioned by positioning the selector class written: .class
driver.find_element_by_css_selector ( ". s_ipt"). send_keys ( " pants") 
the time.sleep (2) 
'' ' 
#CSS positioning positioned composition 
' '' 
#CSS positioned by positioning the selector id written: #id
. driver.find_element_by_css_selector ( "# kw") send_keys ( " pants") 
the time.sleep (2) 
'' ' 
' '' 
#CSS positioned by the positioning tab hierarchy wording: Element> Element 
driver.find_element_by_css_selector ( "span> INPUT" ) .send_keys ( "pants") 
the time.sleep (2) 
'' ' 
' '' 
#CSS property positioned by positioning 
# driver.find_element_by_css_selector ( "[autocomplete = off ]"). send_keys ( ' trousers') 
driver.find_element_by_css_selector ( "[name = 'wd'] "). send_keys ( ' trousers') 
driver.find_element_by_css_selector ( "[type = 'Submit']"). the Click () 
the time.sleep (2) 
'' ' 
' ''find_element_by_css_selector("form.fm > span > input.s_ipt").send_keys("裤子")
driver.find_element_by_css_selector("form#form > span > [type='submit']").click()
driver.find_element_by_css_selector ( "form.fm> span> input.s_ipt "). send_keys ( " pants") 
the time.sleep (2) 
'' ' 

' '' 
. 8 embodiment #By types of the alignment mode, similar wording, just need to By the way you can use to import 
from selenium.webdriver.common.by import By 
driver.find_element (By.ID, "kw"). send_keys ( "pants") 
driver.find_element (By.NAME, "WD"). send_keys ( " pants ") 
driver.find_element (By.CLASS_NAME," s_ipt "). send_keys (" pants ") 
driver.find_element (By.TAG_NAME," the INPUT "). send_keys (" pants ") 
driver.find_element (By.LINK_TEXT," News ") .click () 
driver.find_element (By.PARTIAL_LINK_TEXT," hao "). the Click () 
driver.find_element (By.XPATH," // * [@ class = 'bg s_btn']")
driver.find_element(By.CSS_SELECTOR,"span.bg s_btn_wr > input#su")
'''
time.sleep(2)

driver.quit()

  

Guess you like

Origin www.cnblogs.com/LT-XILI/p/11615497.html