Xpath - 获取检查输入的标签文本

时间:2014-09-22 15:47:33

标签: php dom xpath

有人能指出我正确的方向吗?如果条件是标签中输入复选框的“已检查”,我在获取标签文本时遇到问题。

<label id="idUABFADYAOQA1ADcAOAA_E_label" class="radiobutton_label" onclick="" for="idUABFADYAOQA1ADcAOAA_E">
<input id="idUABFADYAOQA1ADcAOAA_E" class="radiobutton" type="radio" onclick="" checked="checked" name="PEC1"/>
Text i want to get because input is = checked
</label>

<label id="idUABFADgAOQAxADkAOAA_E_label" class="radiobutton_label" onclick="" for="idUABFADgAOQAxADkAOAA_E">
<input id="idUABFADgAOQAxADkAOAA_E" class="radiobutton" type="radio" onclick="" name="PEC1"/>
Text i do not want to get
</label>

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:0)

以下XPath:

//input[@type='radio' and @checked = 'checked']/following-sibling::text()

将返回:

Text i want to get because input is = checked

答案 1 :(得分:0)

您可以使用以下XPath查询:

//input[@checked="checked"]/../text()