HTML
页面包含用户详细信息表。
我需要删除用户。
我可以通过用户名来选择行中的第一个元素。
我需要选择该行上的“删除”按钮来删除该用户。
的HTML
结构为:WebDriver Selenium:需要在表格中选择元素后
<table id="tblUsersGrid" cellpadding="2">
<thead>
<tbody>
<tr class="aboutMeRow" data-parentid="223">
<tr>
<tr>
...
<tr>
<td class="cell cell_278 cell_NameCell">xoxo</td>
<td class="optionIcon overrideFloat orgIcon cell cell_278 gridCell"></td>
<td class="cell cell_278 gridCell">Custom</td>
<td class="cell cell_278 gridCell">qaadmin</td>
<td class="cell cell_278 gridCell">0</td>
<td class="cell gridCell">
<div class="removeAccountIcon"></div>
<td class="cell gridCell">
<div class="editAccountIcon"></div>
</td>
<td></td>
</tr>
所以我可以很容易地通过
driver.findElement(By.xpath("//td[@class='cell_NameCell'][contains(text(),'xoxo')]"))
选择所需的行,但我怎么能达到该行的removeAccountIcon
元素?
我看到很多问题处理选择表内的元素,但没有找到解决这个问题。
有没有办法通过CSS
选择器来做到这一点,而不仅仅是通过Xpath
? (我确信有这个Xpath
解决方案)。
我知道这不是你真正想要的,但你可以找到表,然后迭代每行并使用findElements获取列(td)列表。在列表中,您可以通过索引获取元素以检查用户并获取按钮(这里是一个类似的代码,可以执行此操作http://stackoverflow.com/a/14192252) – Guillermo
嗯,这是一个解决方案。你是对的。但我想有一个表达式(Xpath)来完成这项工作。 – Eliyahu
是的,我想也是...类似这样的东西:// td [contains(text(),'xoxo')/ following-sibling :: td // div [@ class ='removeAccountIcon'] – Guillermo