2014-09-22 36 views
0

我正在编写一个selenium java代码,并且在特定的网页上我想从一组链接中选择链接,其中每个链接在表格中都有一个emebeded文本。我怎样才能在这种情况下选择特定的链接。例如。在获取标签之前选择链接

run title--text 1 
run title--text 2 
run title--text 3 

如何为特定的标题文本选择特定的运行链接?文本不是标签,而只是网页上的简单文本。

我用下面的代码:

verify.text("text 1"); 

只会验证文本的存在,它不会去实现的联系,每一个执行环节被命名为RUN。所以它会识别相应的运行链接?上面的HTML代码是:

<HTML> 
    <HEAD> 
    <TITLE>TEST</TITLE> 
    </HEAD> 
    <BODY> 
    <div align="center"><table class="module" width="630"> 

<tr> 
<th class="banner" width="70">ACTION</th> 
<th class="banner" width="560">REPORT TEMPLATE</th> 
</tr> 





<tr> 

<td class="modulenav" width="70"> 
<table class="innermodule" width="100%"> 



    <tr><td class="moduleNav"><a class="listingLink" 
     href="www.abc.com/">Run</a></td></tr> 

    <tr><td class="moduleNav"><a class="listingLink" 
     href="www.zxc.com">UnShare</a></td></tr> 

    </table> 
    </td> 

    <td> 
    <table class="innerModule" width="100%"> 
    <tr> 
     <td class="label" width="70">Title</td> 
     <td width="490"><span class="listingHead">Incident Performance by Priority</span></td> 
    </tr> 
    <tr> 
     <td class="Label" width="70">Description</td> 
     <td class="listing"></td> 
    </tr> 

    <tr> 
     <td class="Label" width="70">Owner</td> 
     <td class="listing"> Software Engineer&nbsp; Tel: </td> 
    </tr> 

    <tr> 
     <td class="Label" width="70">Shared With</td> 
     <td class="listing"> 

     Software Engineer &nbsp;Tel: <br> 


     </td> 
     </tr> 


     <tr> 
     <td class="label">Report Type</td> 
     <td class="listing">Performance by Priority</td> 
    </tr> 
    </table> 
    </td> 
    </tr> 
    <tr><td class="tableRuleNavy" colspan="2"></td></tr> 

    <tr> 

    <td class="modulenav" width="70"> 
    <table class="innermodule" width="100%"> 



    <tr><td class="moduleNav"><a class="listingLink" 
     href="www.abc.com">Run</a></td></tr> 

    <tr><td class="moduleNav"><a class="listingLink" 
     href="www.cxd.com">UnShare</a></td></tr> 

    </table> 
</td> 



<td> 
    <table class="innerModule" width="100%"> 
    <tr> 
     <td class="label" width="70">Title</td> 
     <td width="490"><span class="listingHead">Incident Trend Analysis Report</span></td> 
    </tr> 
    <tr> 
     <td class="Label" width="70">Description</td> 
     <td class="listing"></td> 
    </tr> 

    <tr> 
     <td class="Label" width="70">Owner</td> 
     <td class="listing">Software Engineer&nbsp; Tel: </td> 
    </tr> 

    <tr> 
     <td class="Label" width="70">Shared With</td> 
     <td class="listing"> 




     Software Engineer &nbsp;Tel: <br> 


     </td> 
    </tr> 


    <tr> 
     <td class="label">Report Type</td> 
     <td class="listing">Trend Analysis</td> 
    </tr> 
    </table> 
</td> 
</tr> 
<tr><td class="tableRuleNavy" colspan="2"></td></tr> 

<tr> 

<td class="modulenav" width="70"> 
    <table class="innermodule" width="100%"> 



    <tr><td class="moduleNav"><a class="listingLink" 
     href="www.sdfds.com">Run</a></td></tr> 



    <tr><td class="moduleNav"><a class="listingLink" 
     href="www.asdg.com">UnShare</a></td></tr> 


    </table> 
</DIV> 
</td> 
</BODY> 
</HTML> 

回答

0

获取web元素列表并遍历它们。 这不是测试 E.g.

List<WebElement> we = findElements(By.cssSelector("tr a")); 

Iterator itor = we.iterator() 
While(itor.hasNext()) { 
    WebElement we = itor.next(); 
    if (we.getText().equals("your visible  text")) { 
     we.click // click link 
    } 
} 
+0

Bcar,就像我说过的,链接的所有可见文本都是RUN,我想从用户那里获得标题值并点击那个特定的“RUN”链接 – ninja67 2014-09-23 06:31:05

相关问题