这是我用来获取具有特定元素的表行元素的表,例如具有' Harvest'在文本中还检查文本是否正在运行'存在于同一个表行中。
<table id="execTable" class="tableHistory jobtable translucent">
<colgroup>
<col class="execid">
<col class="titlecol">
</colgroup>
<tbody>
<tr>
<th>Id</th>
<th>Name</th>
</tr>
</tbody>
<tr id="8571">
<td>8571</td>
<td class="titlecol">
<div id="hitdiv-8571" class="arrow"></div>
<a href="/job?id=Harvest&logs">Harvest</a>
</td>
<td>09-03-2015 09:45:04</td>
<td>-</td>
<td>2m 6s</td>
<td>running</td>
<td><a href="flow?action=restart&id=8571">view/restart</a></td>
</tr>
<tr id="8571-child" class="childRow" style="display: none;"></tr>
<tr id="8566">
<td>8566</td>
<td class="titlecol">
<div id="hitdiv-8566" class="arrow"></div>
<a href="/job?id=mk trained input&logs">mk</a>
</td>
<td>09-03-2015 03:30:00</td>
<td>09-03-2015 04:16:50</td>
<td>46m 50s</td>
<td>succeeded</td>
<td><a href="/flow?action=restart&id=8566">view/restart</a></td>
</tr>
<tr id="8555-child" class="childRow" style="display: none;"></tr>
</table>
我无法获得TR
。
WebElement table = driver.findElement(By.id("execTable"));
List<WebElement> trows = table.findElements(By.tagName("tr"));
答案 0 :(得分:0)
List<WebElement> all = driver.findElements(By.xpath(".//*[@id='execTable']/*"));
for (WebElement a : all) {
if(a.getTagName().equalsIgnoreCase("tr")) { ....}
}
我能够使上述代码正常工作。谢谢!