[英]XPath to find elements
I wouldn't mind a little help with some xpath for selenium. 我不介意为硒提供一些xpath帮助。 From the below HTML I am trying to grab a list of links, from within the articles, but only for the available items. 从下面的HTML中,我试图从文章中获取链接列表,但仅针对可用项目。
<html>
<body>
<div class="listing">
<h3>Available</h3>
<article>
<a href="article.php?id=123">
</article>
</div>
<div class="listing">
<h3>Sold</h3>
<article>
<a href="article.php?id=123">
</article>
</div>
</body>
</html>
Here is what I've got... 这就是我所拥有的...
//h3[. = 'Available']/ancestor::div[1]//article//a
I would point out that the first div (listing) is only available when there are items available for sale. 我要指出的是,只有当有待售商品时,第一个div(清单)才可用。
Use the following XPath 使用以下XPath
//div[h3 = 'Available']/article/a
It will return all a
elements which are in the same div
as h3
elements with the value "Available". 这将返回所有a
这是在相同的元素div
为h3
,其值为“可用”的元素。
The result may seem empty because the a
elements themselves have no values. 结果可能看起来是空的,因为a
元素本身没有值。 But if you try to access the @href
attributes, you'll get a visible result. 但是,如果尝试访问@href
属性,则会看到可见的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.