测试进阶 - selenium之XPATH笔记
1.安装View XPath工具(XPath checker);
- 1. 索引[x]
-
- //div/input[2] 表示:div下面第二个input
- postion()=2 postion()>3 postion<5
- last() last()-1
- 属性定位 @class 例如://div[@class] 表示:有 class属性的div
功能关键字:
- and/[][] , or , not , contains , starts-with ,
- 通配符 * //span[@* = 'bruce'] //*[@*='bruce']
- parent 父节点
- ancestor 祖先节点,包括父节点,层级向上;
- descendant (即://) 表示所有子孙节点 //div[@class='123']//input
- following-sibling 表示当前元素后面同级下的所有节点
- preceding-sibling 表示元素前面同级下的所有节点
XPATH函数:
starts-with() //img[starts-with(@alt, 'div')]
contains() //img[contains(@alt, 'gl')]