要找到包含特定文本的元素的XPath,可以使用XPath的contains()函数。以下是一个包含代码示例的解决方法:
假设有以下HTML代码:
This is a paragraph.
This is another paragraph.
Here is a third paragraph.
要找到包含文本"This is another"的p元素的XPath,可以使用以下XPath表达式:
//p[contains(text(), 'This is another')]
上述XPath表达式使用//
选择所有p元素,然后使用contains(text(), 'This is another')
来过滤只选择包含文本"This is another"的p元素。
通过使用上述XPath表达式,将会得到以下结果:
This is another paragraph.
请注意,如果要匹配的文本是区分大小写的,可以使用contains(text(),'text', 'i')
来进行不区分大小写的匹配。
上一篇:包含特定数据的新矩阵