一尘不染

XPath选择后续同级

selenium

这是我目前拥有的代码:

<div>
<ul class="nav nav-pills nav-stacked">
<li>
<li>
<li>
<li>
<li>
<section>
<span name="merchant">ABZ</span>
</section>
<section>
<span class="glyphicon glyphicon-pencil" name="edit"></span>
<span class="glyphicon glyphicon-remove" name="delete"></span>
</section>
</li>
<li>
<li>
<li>
<li>
</ul>
<div class="add-item bottom" name="new-merchant">
</div>

我尝试了以下方法:

xpath=//span[contains(.,'ABZ')]/following-sibling::section/span[@name='edit']
xpath=//span[contains(.,'ABZ')]/following-sibling::span[1]

我正在使用selenium,我希望它单击ABZ之后的编辑按钮span


阅读 311

收藏
2020-06-26

共1个答案

一尘不染

这个xpath使用您的html在Chrome中为我工作:

//span[contains(text(), 'ABZ')]/../following-sibling::section/span[@name='edit']

编辑

..提升水平的手段。在..从需要选择spansection。然后,following- sibling找到匹配项section的父section项之后span

您原来的选择器匹配span,然后寻找following-siblingspan

2020-06-26