HTML
页包含用户详细信息表。
我需要删除用户。
我可以通过用户名选择该行中的第一个元素。
我需要选择该行上的“删除”按钮才能删除该用户。HTML
结构是:
<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
解决方案)。
最佳答案
Xpath轴preceding-sibling
将帮助您解决问题。您可以在xpath下尝试://td[preceding-sibling::td[contains(text(),'xoxo')]][5]/div[@class='removeAccountIcon']
请让我知道这对你有没有用。
关于css - WebDriver Selenium:在某些元素之后需要在表中选择元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31372465/