2014-09-27 202 views
0

在selenium中如何點擊表中嵌入的超鏈接,在這裏我要點擊鏈接,這個鏈接是在數據表的第一個條目。在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

你能分享哪個網站?或者頁面的DOM層次結構? – sheeptest 2014-09-27 12:32:27

回答

0

這是我要如何只用你貼

WebElement hyperlink = driver.findElement(By.cssSelector("table.table a.ng-binding")); 

hyperlink.click(); 
片斷做

當然太多了火柴不適用於此,但我相信你會得到代碼背後的一般想法。

+0

感謝您的建議正常工作。 – Anamika 2014-09-29 05:10:00

相關問題