项目中一些使用xpath函数的复杂例子,记录于此
1. 使用starts-with:寻找id属性以res开头的div元素。其中@后面的id可以替换成元素的任意其他属性
//div[starts-with(@id,'res')]
2.使用contains和and
//span[contains(@id , '_Test') and contains(. , 'KPI')]
3.使用descendant(当前节点的子孙节点)
//div[starts-with(@id,'res')]/descendant::img
4.使用ancestor(当前节点的所有父节点)
//div[starts-with(@id,'res')]/ancestor::div[starts-with(@id,'res')]
5.使用text() 获取当前元素的文本信息,不包括子元素的文本,等同于“.”
//span[@id='idHeaderTitleCell' and contains(text(),'QuickStart')]
6.使用/..表示当前节点的父节点
//a[contains(.,"div")]/..