首页 技术 正文
技术 2022年11月9日
0 收藏 844 点赞 2,254 浏览 986 个字

1.查看页面元素:ID、class、type、name等。

Selenium之元素定位

2.通过webdriver的方法定位:

Selenium之元素定位

find_element_by_name() 
find_element_by_id() 
find_element_by_class_name() 

Selenium之元素定位

browser.find_element_by_xpath();

绝对路径:find_element_by_xpath(“/html/body/div[1]/div[1]/div/div[1]/div/form/span[1]/input”)

相对路径:

find_element_by_xpath(“//input[@id=’kw’]”)

find_element_by_xpath(“//*[@name=’wd’]”)

find_element_by_css_selector() 

一般class是用.标记,id是用#标记,标签名直接写具体标签名就好了

Selenium之元素定位

find_element_by_link_text()
find_element_by_partial_link_text()

Selenium之元素定位

3.通过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,u”新闻”)
find_element(By.PARTIAL_LINK_TEXT,u”新”)
find_element(By.XPATH,”//*[@class=’bg s_btn’]”)
find_element(By.CSS_SELECTOR,”span.bg s_btn_wr>input#su”) 
前提是导入:from selenium.webdriver.common.by import By

4.JS定位:

id定位:document.getElementById()
name定位:document.getElementsByName()
tag定位:document.getElementsByTagName()
class定位:document.getElementsByClassName()
css定位:document.querySelectorAll()

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,489
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,904
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,737
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,490
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,128
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,291