-------------------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) 当前元素的下级元素
python+selemium 中find_element_by_xpath()的用法
最新推荐文章于 2024-06-12 20:57:59 发布