css定位.py
from selenium import webdriver#引入By类:from selenium.webdriver.common.by import Bydriver = webdriver.Chrome()#通过class属性定位输入框和百度一下、点表示通过class属性来定位元素:driver.find_element_by_css_selector(".s_ipt")driver.find_element_by_css_selector(".bg s_btn")#通过id属性定位输入框和百度一下、井号表示通过id属性来进行定位元素:driver.find_element_by_css_selector("#kw")driver.find_element_by_css_selector("#su")#通过标签名定位、注意标签名重复概率大:driver.find_element_by_css_selector("input")#通过父子关系定位父标签是span、查找所有标签名叫input的子元素:driver.find_element_by_css_selector("span>input")#通过属性定位:driver.find_element_by_css_selector("[autocomplete=off")driver.find_element_by_css_selector("[name=‘wd‘]")driver.find_element_by_css_selector("[type=‘submit‘]")#组合定位、父标签span有一个class属性值叫bg s_ipt_wr下面有一个子元素标签名叫input、子元素的class属性值叫s_ipt、:driver.find_element_by_css_selector("span.bg s_ipt_wr>input.s_ipt")driver.find_element_by_css_selector("span.bg s_btn_wr>input#su")#通过By定位元素、统一调用find_element()方法、通过By来声明定位的方法、传入对应定位方法的定位参数、第一个参数是定位的类型、由By提供、第二个参数是定位的具体方式:driver.find_element(By.ID,"kw")driver.find_element(By.NAME,"wd")driver.find_element(By.CLASS_NAME,"s_ipt")driver.find_element(By.TAG_NAME,"inpu")driver.find_element(By.LINK_TEXT,"新闻")driver.find_element(By.PARTIAL_LINK_TEXT,"新")driver.find_element(By.XPATH,"//*[@class=‘bg s_btn‘]")driver.find_element(By.CSS_SELECTOR,"span.bg s_btn_wr>input#su")
相关推荐
qiupu 2020-11-04
多读书读好书 2020-11-03
RedCode 2020-10-28
jiedinghui 2020-10-25
Ladyseven 2020-10-22
hellowzm 2020-10-12
zuncle 2020-09-28
Ladyseven 2020-09-11
jiedinghui 2020-09-07
xiaohuli 2020-09-02
葉無聞 2020-09-01
impress 2020-08-26
ThikHome 2020-08-24
nicepainkiller 2020-08-20
hellowzm 2020-08-18