如何选择(或点击)表格中的按钮

时间:2016-11-01 00:36:15

标签: selenium

我有一个如下表所示的两个按钮,如何选择' FIRST'行?

<table id="comms-table" class="table table-condensed">
<tbody>
<tr><th class="bordered" style="text-align: center;" width="50">Status</th><th class="bordered" width="130">Component</th><th class="bordered">Last heart-beat</th></tr>
<tr class="data_row">
<td style="text-align: center;"><button class="btn btn-mini btn-success">&nbsp;&nbsp;&nbsp;&nbsp;</button></td>
<td class="bordered">FIRST</td>
<td class="bordered">5 seconds ago</td>
</tr>
<tr class="data_row">
<td style="text-align: center;"><button class="btn btn-mini btn-success">&nbsp;&nbsp;&nbsp;&nbsp;</button></td>
<td class="bordered">SECOND</td>
<td class="bordered">17 seconds ago</td>
</tr>
</tbody>
</table>

1 个答案:

答案 0 :(得分:0)

试试这个:

WebElement we = driver.findElement(By.xpath("//*[contains(text(),'FIRST')]/preceding::button[1]"));
we.click();