2016-07-18 4 views
0
<div class="btm0">Question 1 
</div><span class="small"></span> 
<span id="form2"> 
<span id="form2:j_idt4598" style="display: none;"></span><ul id="form2:radioButton" class="controls full-width"> 
<li> 
<input class=" firepath-matching-node" name="form2:radioButton" id="form2:radioButton:0" type="radio"><label for="form2:radioButton:0"> Yes</label></li> 
<li> 
<input class=" firepath-matching-node" name="form2:radioButton" id="form2:radioButton:1" type="radio"><label for="form2:radioButton:1"> No</label></li> 
</ul> 
<span id="form2:errMessage"></span> 
</span> 
<div class="btm0">Question 2 
</div><span class="small"></span> 
<span id="form1"> 
<span id="form1:j_idt4617" style="display: none;"></span><ul id="form1:radioButton" class="controls full-width"> 
<li> 
<input class=" firepath-matching-node" name="form1:radioButton" id="form1:radioButton:0" type="radio"><label for="form1:radioButton:0"> Yes</label></li> 
<li> 
<input class=" firepath-matching-node" name="form1:radioButton" id="form1:radioButton:1" type="radio"><label for="form1:radioButton:1"> No</label> 

레이블 및 옵션 버튼이있는 위의 간단한 페이지가 있습니다.XPath를 사용하여 라디오 버튼 선택

XPath를 사용하여 '질문 1 - 예'를 선택하고 싶습니다.

올바른 '예'옵션 (질문 1 또는 질문 2 일 수 있음)을 선택하는 고유 한 XPath를 만드는 쉬운 방법이 있습니까? XPath를 하드 코딩하고 싶지 않습니다.

나는 부분적인 해결책을 시도했지만 난 단지 두 번째 'YES'옵션을 선택하세요 :

//*[contains(text(),'Question 1')]/following::label[contains(text(),'Yes')] 

답변

2

확실하지 않음 이것이 원하는 것이 아니라면 샘플 결과를 제공하여 질문을 명확히하십시오.

+0

감사합니다. Markus, 내 문제에 대해 더 나은 해결책입니다. – Vikram

0

내가 필요로 대답과 함께 행복하지 정말 시도 후 몇 가지 솔루션을 얻을 수 있지만이었다 변경 내 xpath YES를 기반으로하거나 옵션 버튼

의 NO YES를위한 : NO에 대한

//*[contains(text(),'Question 1')]/./following::li[1]/label[contains(text(),'Yes')] 

:

//*[contains(text(),'Question 1')]/./following::li[2]/label[contains(text(),'Yes')] 

위의 해결책에서 알 수 있듯이 li[] 값을 전환해야합니다.

위의 해결 방법을 통해 옵션을 정확히 찾아 낼 수 있습니다.

//div[contains(text(),'Question 1')]/following::label[position() <= 2 and contains(text(),'Yes')] 

: 이것은 당신이 요구하는 것입니다,하지만 당신은 div 후 바로 2 개 label 요소로 XPath 표현식의 범위를 제한하려는 경우, 당신은 position() 기능을 사용할 수 있는지