这是我的HTML脚本:
如何捕获第十行中的link元素? HTML image
<table id="dataTableParticipantSearchResults" class="display" width="100%" cellspacing="0" cellpadding="0" border="0">
<thead>
<tr align="left">
<th class="ui-state-default" width="20%" style="width: 154px;">
<div class="DataTables_sort_wrapper"></div>
</th>
<th class="ui-state-default" width="20%" style="width: 96px;"></th>
<th class="ui-state-default" width="15%" style="width: 69px;"></th>
<th class="ui-state-default" width="10%" style="width: 44px;"></th>
<th class="ui-state-default" width="20%" style="width: 156px;"></th>
<th class="ui-state-default" width="15%" style="width: 68px;"></th>
</tr>
</thead>
<tbody>
<tr class="odd" align="left">
<td><a href="LINK"></a></td>
</tr>
&#13;
2.如何存储该值,以便我可以调用相同的值来访问链接元素?
答案 0 :(得分:0)
您总是可以通过首先识别根表ID找到这些类型的超链接 - 在这种情况下它将是这样的:
WebElement table = driver.findelement(by.id("dataTableParticipantSearchResults"));
现在您可以使用Xpath或Css Selector来选择链接
试试这个:
table.findelement(by.cssSelector("a[href='LINK']")).click();
或尝试
table.findelement(by.linktext("LINK")).click();
或尝试
table.findelement(by.xpath(".//*[@id='dataTableParticipantSearchResults']/tbody/tr/td[0]")).click();
让我知道这些是否有效....欢呼!
答案 1 :(得分:0)
U可以将值存储在WebElement中并多次调用。
WeElement link = table.findelement(by.xpath(“.//* [@ id ='dataTableParticipantSearchResults'] / tbody / tr / td [9]”));
现在多次调用它:
link.click(); ---------第一次
link.click(); ---------第二次
等等.....欢呼!