想要使用selenium webdriver使用xpath或任何其他定位器来识别JSP核心<c:if>标记的元素

时间:2017-10-02 12:08:07

标签: java selenium xpath

<tr class="odd" role="row">
<td>PRODTUT020</td>
<td>Product for tours</td>
<td>
<td>
<ul class="icons-list">
<c:if test="true">
<li class="text-info-600">
<a href="edit-se-product_mst-90" title="View">
<i class="icon-eye"/>
</a>
</li>
</c:if>
</ul>
</td>
</tr>

上面是html正文。想要点击icon-eye元素。我们如何使用selenium定位器识别这个元素?

2 个答案:

答案 0 :(得分:1)

这个XPath,

/u

将选择//tr[td="PRODTUT020"]//i[@class="icon-eye"] 元素i属性值@class位于icon-eye元素tr元素下td元素的字符串值为PRODTUT020的{​​{1}}元素

根据您在一般情况下更加不变的情况,您可以将PRODTUT020更改为Product for tours - 两者都适用于您展示的案例。

它避免了必须通过//跳过它来命名命名空间元素。

答案 1 :(得分:1)

如果您想在i元素中提取c:if,可以使用以下表达式

'//*[name()="c:if" and @test="true"]//i'
相关问题