WebDriver CSS、By定位

WebDriver CSS、By定位

百度搜索输入框

class定位:

find_element_by_css_selector(".s_ipt")

id定位:

find_element_by_css_selector(".kw")

tag定位 :

find_element_by_css_selector("input")

tag层级:

find_element_by_css_selector("span > input")

属性:

find_element_by_css_selector("[name=kw]")

组合定位:

find_element_by_css_selector("from#from > span >input#kw")

字符串:

find_element_by_css_selector("[class*s_ipt_wr]") #class 属性含wr的字符串

find_element_by_css_selector(“[class^=s])#class以s字符串开头的

find_element_by_css_selector(”[class$=wr]")#class以wr字符串结尾的

find_element_by_css_selector("from > input:nth-chind(2)")#标签下面的第2个input的因素

find_element_by_css_selector("from > input:nth-last-child(1) ") #选择倒数第一个p元素



By定位:

#导入 from selement.webdriver.common.by import By

find_element(By.ID,"kw")

find_element(By.NAME,"WD")

find_element(By.CLASS_NAME,"s_ipt")

find_element(By.TAG_NAME,"input")

find_element(By.LINK_TEXT,"新闻")

find_element(By.PARTIAL_LINK_TEXT,"新")

find_element(By.XPATH,"//*【@class='bg s_btn']")

find_element(By.CSS_SELECTOR,"span.bg s_btn_wr>input#su")

posted @ 2020-10-14 10:02  Catonce  阅读(272)  评论(0)    收藏  举报