包含一个属性且其父级的父级包含另一个属性的 XPath 元素
这是我在这里发表的第一篇文章,因为我看到了很多很棒的答案,所以我想我应该尝试一下。
我正在尝试使用 XPath 来获取 HTML 文档中的特定元素。下面是一个基于 Google 网页的示例:
<html>
<head>
<title>XPath Test</title>
</head>
<body>
<form name='f'>
<table>
<tbody>
<tr>
<td>
<input name='q' type="text" />
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
使用上面的示例(为了寻求帮助而进行了简化),我希望能够找到 name='q' 且具有祖先是 5 个父母,名字='f'。
例如,如果我要使用 SWAT 的语法来执行此操作,SWAT 是一个开源 Web 自动化测试库,位于 http: //ulti-swat.wikispaces.com,语法如下:
|AssertElementExists|Expression|name=q;parentElement.parentElement.parentElement.parentElement.parentElement.name=f|input|
我刚刚开始学习 XPath,并试图了解如何将谓词与轴结合起来。是否可以使用 XPath 执行这样的表达式?如果可以请有了解的人帮忙吗?
This is my first post here and since I've seen many great answers I thought I'd give it a try.
I'm trying to use XPath to obtain a specific element in an HTML document. Here is an example based off of the Google web page:
<html>
<head>
<title>XPath Test</title>
</head>
<body>
<form name='f'>
<table>
<tbody>
<tr>
<td>
<input name='q' type="text" />
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
Using the example above (which is simplified for the purposes of asking for help), I would like to be able to find the input element whose name='q' and who has an ancestor who is 5 parents up with the name='f'.
For example if I were to do this in the syntax of S.W.A.T. which is an open-source web automation testing library located at http://ulti-swat.wikispaces.com, the syntax would be as follows:
|AssertElementExists|Expression|name=q;parentElement.parentElement.parentElement.parentElement.parentElement.name=f|input|
I just started learning XPath and am trying to understand how to combine predicates with axes. Is it possible to do expressions like this with XPath? If so can someone knowledgeable please help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以执行以下操作:
或者
您可以使用此桌面 XPath Visualizer 来测试您的 XPath 表达式。 可以在此处找到基本教程。
You could to do:
or
You can use this desktop XPath Visualizer to test your XPath expressions. A basic tutorial can be found here.