码迷,mamicode.com
首页 > Web开发 > 详细

selenium-xpath选择操作web元素

时间:2019-07-01 10:30:32      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:sele   foo   css   选择器   follow   写法   OWIN   button   语法   

1.根据属性选择

(1)//*[@style]选择所有具有style属性的元素   #css写法  *[style]

(2)//p[@spec=‘len2‘选择所有具有spec值为len2的元素   #css写法p[spec=len2]

2.根据id选择

id,class也是属性

//div[@id="food"]  #css写法#food

//div[@class="cheese"]  #css写法.cheese

3.子元素选择

选择属于其父元素的第n个某个类型的子元素

//p[2]等价于css写法p:nth-of-type(2)

//*[@id-"food"]/p[1]等价于css写法#food>p:nth-of-type(1)

//*[2]等价于//*[position()-2]等价于*:nth-child(2)

//*[@id-"food"]/*[position()-3]

支持其他的比较操作符

//*[@id-"food"]/*[position()<3]

//*[id-"food"]/*[position()<-3]

选择属于其父元素的倒数第n个子元素

//*[@id-"food"]/*[last()-1]等价于

//*[@id-”food"]/*[position()-last()-1]

多选://*[@id="food"]/*[position()>last()-3]

4.组选择

多个表达式在一起

css用,隔开

比如p,button

xpath用|隔开

//p|//button

5.其他选择语法

相邻兄弟选择器

following-sibling

preceding-sibling

xpath擅长的

..上层元素

 

selenium-xpath选择操作web元素

标签:sele   foo   css   选择器   follow   写法   OWIN   button   语法   

原文地址:https://www.cnblogs.com/iamshasha/p/11112610.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!