如何让xpath previous-sibling为这个表工作

时间:2012-12-04 13:55:32

标签: xpath

我有一个表格,我需要查找是否选中了与单元格对应的复选框,例如,我需要查看是否选中了复选框id = 830,这是否是DeviceHelp的兄弟。

同样对于元素联系,我必须检查复选框id =“72”是否已选中/未选中

我只能依靠文本元素(联系人,DeviceHelp等)来获取复选框状态,而不是可能更改的复选框ID。

<tr class="row active" style="display: table-row;">
<td>
<input id="72" class="rowcheck" type="checkbox" value="true" name="ModesForUi[0].Allow" categoryid="58" disabled="">
<input type="hidden" value="false" name="ModesForUi[0].Allow">
</td>
<td> Administration - Read </td>
<td>
Contact
<input id="ModesForUi_0__ResourceID" type="hidden" value="72" name="ModesForUi[0].ResourceID">
<input id="ModesForUi_0__ModeID" type="hidden" value="12185" name="ModesForUi[0].ModeID">
</td>
<td> Controls access to Search Contacts link and to view contact details page. Navigate to Menu\Advanced\More </td>
</tr>
<tr class="row active" style="display: table-row;">
<td>
<input id="830" class="rowcheck" type="checkbox" value="true" name="ModesForUi[1].Allow" categoryid="58" disabled="">
<input type="hidden" value="false" name="ModesForUi[1].Allow">
</td>
<td> Administration - Read </td>
<td>
DeviceHelp
<input id="ModesForUi_1__ResourceID" type="hidden" value="830"     name="ModesForUi[1].ResourceID">
<input id="ModesForUi_1__ModeID" type="hidden" value="12186"     name="ModesForUi[1].ModeID">
</td>
<td> Controls access to Help icon displayed next to logout icon and next to the menu.     </td>
</tr>

尝试过以下操作,但我没有获得复选框值

"ancestor::td[1]/input[1]/preceding-sibling::td[normalize-space(text())='DeviceHelp']")

//tr[position()>1]/td[normalize-space(text())='DeviceHelp*']/parent::td/preceding-sibling::td/input@value 

请xpath专家你能否了解上述路径的错误以及如何进入复选框?

谢谢!

1 个答案:

答案 0 :(得分:0)

我想我知道你想要到达的地方......

尝试使用设备帮助:

/root/tr/td[normalize-space(text())='DeviceHelp']/../td[1]/input[1]/@value

这是联系方式:

/root/tr/td[normalize-space(text())='Contact']/../td[1]/input[1]/@value

“root”就是您从哪个节点开始,我添加了本地测试,因为XML片段不完整。

修改

试试这个:

//tr/td[normalize-space(text())='DeviceHelp']/../td[1]/input[1]/@value

//tr/td[normalize-space(text())='Contact']/../td[1]/input[1]/@value