Selenium之find_element_by_css_selector三种定位方法,附代码!
2021-01-16 23:11
标签:pycha bin file chrome usr get 需要 software toc Selenium之find_element_by_css_selector三种定位方法,附代码! 标签:pycha bin file chrome usr get 需要 software toc 原文地址:https://www.cnblogs.com/gengwulovestudy/p/13373151.html# #!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time : 2020/7/24 15:32
# @Author : Gengwu
# @FileName: By_css_seleclor.py
# @Software: PyCharm
from selenium import webdriver
from time import sleep
driver=webdriver.Chrome()
#driver.get(‘https://www.baidu.com/‘)
#1:通过id来定位
#driver.find_element_by_css_selector("#kw").send_keys("seleniumw我要自学网") #dlement后面不需要s,通过id来定位前面需要加#号+id
#2:通过class来定位
#driver.find_element_by_css_selector(‘.s_ipt‘).send_keys(‘seleniumw我要自学网‘) #class来定位,class前面+.
#3:通过属性来定位
#driver.find_element_by_css_selector("[autocomplete=‘off‘]").send_keys(‘seleniumw我要自学网‘) #属性要在[]里面
sleep(2)
driver.find_element_by_id(‘su‘).click()
sleep(2)
driver.quit()
上一篇:HTML事件
文章标题:Selenium之find_element_by_css_selector三种定位方法,附代码!
文章链接:http://soscw.com/index.php/essay/42917.html