【发布时间】:2017-11-02 09:03:21
【问题描述】:
我注意到使用 xpath 轴方法有时会返回错误的节点。我有两个例子:
网址:“http://demo.guru99.com/v1/”
<tr>
<td align="center">
<img src="../images/1.gif">
<img src="../images/3.gif">
<img src="../images/2.gif">
</td>
</tr>
我可以通过轴方法“//td//child::img”选择三个img元素。但是,当我使用“//td//following-sibling::img”时,它仍然可以返回第二个和第三个img 元素。据我所知,孩子和兄弟姐妹是两个不同的东西,为什么会这样呢?
网址:http://demo.guru99.com/selenium/guru99home/
<div class="rt-grid-12 rt-alpha rt-omega" id="rt-feature">
<div class="rt-grid-6 ">
<div class="rt-block">
<h3>
Desktop, mobile, and tablet access</h3>
<ul>
<li>
<p>
Free android App</p>
</li>
<li>
<p>
Download any tutorial for free</p>
</li>
<li>
<p>
Watch video tutorials from anywhere </p>
</li>
</ul>
<p>
<a href="https:/play.google.com/store/apps/details?id=com.vector.guru99&hl=en"><img alt="" src="images/app_google_play(1).png"></a></p>
</div>
</div>
<div class="rt-grid-5 ">
<div class="rt-block">
<img src="images/logo_respnsivsite.png"><br>
</div>
</div>
</div>
在这里,如果我使用“//div[@id='rt-feature' and (@class='rt-grid-12 rt-alpha rt-omega')]//following-sibling::div” , 那些应该是子元素的 div 元素仍然算作兄弟元素
使用“//div[@id='rt-feature' and (@class='rt-grid-12 rt-alpha rt-omega')]//parent::div”,self 元素及其子 div 元素都算作父元素。
这让我很困惑,请帮助我。
【问题讨论】:
-
第一种情况下正确的 xpath 在 td 之后应该只有一个斜杠 -
//td/following-sibling::img。它不会返回任何东西。我希望大师能用两个斜线解释这种行为