python+selemium 中find_element_by_xpath()的用法

-------------------xpath定位--------
$x(’/’) xpath console
//div/* 等价于css中的 $$('div>’)
//
[@id=‘name’] @是语法 属性值 id后的必须带‘’
//div[@class=‘vegetable’] // 后面必须带有元素类型 可以是通配符,可以是具体的div span 等!!!!!!!!
//[@style] 没有指定特定值,也可以!!!
//div[@class=‘vegetable’][2] 类似于css伪类 div.class.nth-of-type(2)
//
[2] 所有父元素排行第二的元素
----------------------指定位置元素---------------------------
//div[last()-1] 代表倒数第二个元素
//div[last()] 代表最后一个的元素
//div[position()=2] 表示div的位置位于2的元素 等价于 div:nth-child(2)
//div[position()>=3] 大于等于三个元素 1 2 3
//div[position()>=last()-2] 最后几个元素 345
------------------取偶数--------------------------
for i in range(3):#for 循环
if i%2==0:
xpath="//select/div[%s]"%i
------------------组选择--------------------------
| 相当于css的, 相邻元素选择器
xpath 轴概念可定与当前节点的节点集
//div[@id=‘food’]/following-sibling::span 相当于css的^ id='food’下所有 span 属性的元素
//div[@id=‘food’]/following-sibling::span[2] 相当于css的^ id='food’下第二个 span 属性的元素
//div[@id=‘food’]/following-sibling::span[last()] 相当于css的^ id='food’下所有 span 属性的元素
//div[@id=‘food’]/preceding-sibling::span 相当于css的^ id='food’前所有 span 属性的元素
-----------------------父选择--------------------
… 当前元素的父元素
//div(./p) 当前元素的下级元素

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值