2014-09-22 83 views
2

任何人都可以指向正確的方向嗎?如果條件是標籤內輸入複選框的「已選中」,我在獲取標籤文本時遇到問題。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> 

任何幫助,非常感謝。

回答

0

以下XPath:

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

將返回:

Text i want to get because input is = checked 
+0

非常感謝隊友! – media4m 2014-09-22 16:03:08

0

您可以使用下面的XPath查詢:

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

什麼也沒有返回 – media4m 2014-09-22 15:53:12

+0

哦,我明白了。它不是文本(),它是下一個兄弟姐妹...其次。將更新帖子 – hek2mgl 2014-09-22 15:54:47