2016-07-18 25 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 - はい」を選択します。

固有のXPathを作成する簡単な方法がありますが、正しい「はい」オプション(質問1または質問2)を選択しますか?私はXPathをハードコードしたくありません。

私は部分的な解決策を試してみたが、私は唯一の2番目の「YES」オプションを選択します:

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

答えて

2

わかりませんこれがあなたが探しているものでない場合は、おそらくいくつかのサンプル結果を提供して、あなたの質問を明確にしてください。

+0

Thanks Markus、これは私の問題の解決策です。 – Vikram

0

私が持っているとして、私は答えに満足して試した後、いくつかの解決策を得ることができましたが、実際にはありませんYES YES用またはオプションボタン

のNOに基づいて私のxpathを変更するには: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()機能を使用できるかどう

関連する問題