I want to extract the first value which has the property selected = "selected"
using XPath extractor. But it doesn't seem to work for me.
The html which i'm extracting the value from is:
< select id="ddLocation" name="ddLocation" class="DDlocation" size="1" onchange="jsf.util.chain(this,event,'onLocationChange();,'mojarra.ab(this,event,\'valueChange\',\'@this\',0)')"> <br>
< option value="43" selected="selected">Pune</option> <br>
< option value="44">Agra< /option> <br>
< option value="45">Guntur< /option> <br>
< option value="46">Kochi< /option> <br>
< option value="73">Kothrud< /option> <br>
< option value="153">Ratnagiri< /option> <br>
< option value="156">Baner< /option>
My XPath query is:
//select[@id="ddLocation"]/option[1]/@value
Is it wrong?
Can anyone suggest me any better / right approach please?
Your xml is not in proper format
It has lot of spaces in-front of option and select is not closed at end.
<select id="ddLocation" name="ddLocation" class="DDlocation" size="1" onchange="jsf.util.chain(this,event,'onLocationChange();,'mojarra.ab(this,event,\'valueChange\',\'@this\',0)')">
<option value="43" selected="selected">Pune </option>
<option value="44">Agra</option>
<option value="45">Guntur</option>
<option value="46">Kochi</option>
<option value="73">Kothrud</option>
<option value="153">Ratnagiri</option>
<option value="156">Baner</option>
</select>
Finally, your XPATH works as expected.
//select[@id="ddLocation"]/option[1]/@value
It gives output as 43
If you use below XPATH, it gives result according to where attribute is selected=selected
//select[@id='ddLocation']/option[@selected='selected']/@value
I have not tested using JMeter but am checking XPATH on XMLSPY.
Since you are using XPath Extractor to parse HTML (not XML!..) response ensure that Use Tidy (tolerant parser) option is CHECKED (in XPath Extractor's control panel).
And use better refined xpath query from Siva's answer below.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With