Selenium Webdriver和Xpath:复杂的选择

时间:2013-09-11 07:44:11

标签: xpath selenium selenium-webdriver

所以我的结构在某些时候看起来像这样。我需要使用xpath选择具有“选择”链接的文本ShapeCSR。这两个文本都出现在同一行中。

<td>
    <img class="imHeader" alt="" src="include/img/context/level_dash.gif"></img><img class="imHeader" alt="" src="include/img/context/icon_telco_level.gif"></img>
    ShapeCSR
</td>
<td> 
    … 
</td>
<td>
    <a id="lnk_LEVEL_2010" href="jfn?isLevel=true&level=L4%3A2010&mfunc=614&cfunc=615&oid=L4%3A2072&ctx=L&jfnRC=5">
          Select
    </a>
</td>

1 个答案:

答案 0 :(得分:0)

您的问题不够具体,但我假设您有一个<table> <tr>,您想要在{{<td>时选择"ShapeCSR" <tr> 1}}包含<td>,其中包含文字"Select"

试试这个:

WebElement yourLink = webDriver.findElement(By.xpath("//tr[td/a[contains(text(),'Select')]]/td[contains(text(),'ShapeCSR')]"));