概述

这里主要是列举一些常用的字符串匹配函数,以便后期使用者参考。

函数

contains:是否包含特定子字符串

语法

tagname[contains(@attribute, 'value')]

tagname:标签名称 attribute: 属性名称 value:用于和属性值比对的字符串

示例

下面的例子是判断id的值是否包含saladbowl,来查找div的。
image.png

starts-with:是否以指定字符串开头

语法

tagname[starts-with(@attribute, 'value')]

tagname:标签名称 attribute: 属性名称 value:用于和属性值比对的字符串

示例

image.png

ends-with: 是否以指定字符串结尾

语法

tagname[ends-with(@attribute, 'value')]

tagname:标签名称 attribute: 属性名称 value:用于和属性值比对的字符串 ch

chrome浏览器暂不支持,具体原因如下:
image.png
链接
浏览器,比如此处的chrome目前只支持xpath1.0,而ends-with是2.0的语法,所以暂不支持。

参考

XPath Contains Text | XPath Starts With, Ends With,element%20available%20for%20this%20XPath.)