在selenium中如何点击嵌入在表格中的超链接,在这里我要点击链接,此链接位于数据表的第一个条目。
<table class="table table-bordered">
<thead>
<tr></tr>
</thead>
<tbody>
<tr class="ng-scope" ng-repeat="item in view_data">
<td>
<a class="ng-binding" title="Click to View Agent Profile" ng-href="#/agent/profile/46" href="#/agent/profile/46"></a>
</td>
<td class="ng-binding">
1000008
</td>
<td class="ng-binding"></td>
<td class="ng-binding"></td>
<td class="ng-binding"></td>
<td class="ng-binding"></td>
<td class="ng-binding"></td>
<td></td>
</tr>
<tr class="ng-scope" ng-repeat="item in view_data"></tr>
<tr class="ng-scope" ng-repeat="item in view_data"></tr>
<tr class="ng-scope" ng-repeat="item in view_data"></tr>
<tr class="ng-scope" ng-repeat="item in view_data"></tr>
</tbody>
</table>
我尝试了下面的代码,但它不起作用..
WebElement tableLink = driver
.findElement(By
.xpath("//*table[@class='table table-bordered']/thead/tbody tr[@id='ng-scope']/td[@class='ng-binding']/a"));
tableLink.click();
答案 0 :(得分:0)
以下是我仅使用您发布的代码段进行操作的方法
WebElement hyperlink = driver.findElement(By.cssSelector("table.table a.ng-binding"));
hyperlink.click ();
当然,太多的比赛对此无效,但我确信你会得到代码背后的一般概念。