如何使用高级 Xpath 方法定位元素?
How to locate element using advance Xpath method?
我有以下 HTML 代码片段:
<div class="pagging-box status-border status-border">
<div class="left-container">
<div>
<div class="clientid-hover">
<h4>AAB52</h4>
<div class="hover-title" style="display: none;">
<p>AAB52</p>
</div>
</div>
<div class="clientid-hover-state pl-info">
<h4>CO</h4>
</div>
<div class="client-name-hover">
<h4>Daniel-old Polar-old</h4>
</div>
<p class="contacting-client">Interview Partially Co..</p>
</div>
</div>
<div class="right-container">
<div class="start-session pull-right">
<a href="javascript:void(0)");" class="login-button">
<i class="fa fa-2x fa-play-circle continue-session"></i>
</a>
</div>
</div>
</div>
我想根据<h4>AAB52</h4>
文本定位Anchor标签。我试图找到与兄弟姐妹相同的位置 xpath
//div[h4[contains(. , "AAB56")]]/following-sibling::div[1]
(xpath
不正确,因为它定位的是 AAB52
文本的第二个 div
立即数)
following-sibling
对上下文节点的父节点进行操作,因此您首先需要走到正确的上下文节点:
//h4[. = 'AAB52']/../../../following-sibling::div[1]/div/a
或者您可以使用:
//div[./div/div/h4 = 'AAB52']/following-sibling::div[1]/div/a
我有以下 HTML 代码片段:
<div class="pagging-box status-border status-border">
<div class="left-container">
<div>
<div class="clientid-hover">
<h4>AAB52</h4>
<div class="hover-title" style="display: none;">
<p>AAB52</p>
</div>
</div>
<div class="clientid-hover-state pl-info">
<h4>CO</h4>
</div>
<div class="client-name-hover">
<h4>Daniel-old Polar-old</h4>
</div>
<p class="contacting-client">Interview Partially Co..</p>
</div>
</div>
<div class="right-container">
<div class="start-session pull-right">
<a href="javascript:void(0)");" class="login-button">
<i class="fa fa-2x fa-play-circle continue-session"></i>
</a>
</div>
</div>
</div>
我想根据<h4>AAB52</h4>
文本定位Anchor标签。我试图找到与兄弟姐妹相同的位置 xpath
//div[h4[contains(. , "AAB56")]]/following-sibling::div[1]
(xpath
不正确,因为它定位的是 AAB52
文本的第二个 div
立即数)
following-sibling
对上下文节点的父节点进行操作,因此您首先需要走到正确的上下文节点:
//h4[. = 'AAB52']/../../../following-sibling::div[1]/div/a
或者您可以使用:
//div[./div/div/h4 = 'AAB52']/following-sibling::div[1]/div/a