I would know if it's possible to find all elements that match a certain string, using xpath. For example, suppose I have this page:
我想知道是否可以使用xpath找到与某个字符串匹配的所有元素。例如,假设我有这个页面:
<html>
<head>
<title></title>
</head>
<body>
<form id="form1">
</form>
<p class="test"></p>
<p class="test"></p>
<p class="test"></p>
<p class="test"></p>
</body>
</html>
If I search for this string<form id="form1">
I would get the first form element, instead if I search for this string <p class="test"></p>
I would get all the paragraphs elements. Is it possible? Something like //*[matches(., string)]
I'm at the beginning, so any suggestions will be appreciated.
如果我搜索这个字符串
1 个解决方案
#1
1
Try this using xpath :
//form[@id="form1"]
Output :
<form id="form1">
</form>
The rest :
//p[@class="test"]
and if you want a partial match :
如果你想要部分匹配:
//p[contains(@class, "tes")]
#1
1
Try this using xpath :
//form[@id="form1"]
Output :
<form id="form1">
</form>
The rest :
//p[@class="test"]
and if you want a partial match :
如果你想要部分匹配:
//p[contains(@class, "tes")]