Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to I get in xpath the value of the option and not the display value?

Tags:

html

xpath

Consider this example

<select>
<option value="http://www.test1.com"> 1 </option>
<option value="http://www.test2.com"> 2 </option>
<option value="http://www.test3.com"> 3 </option>
</select>

How to I get in xpath the value of the option and not the display? Meaning, I want to get the value of the option element - http://www.test1.com for example and not 1, 2 or 3.

like image 694
Ronen Avatar asked Jan 26 '26 05:01

Ronen


2 Answers

By position:

/select/option[1]/@value

By content:

/select/option[.=1]/@value

or

/select/option[normalize-space()='1']/@value

If you want the set of all values, simply use

/select/option/@value
like image 44
Mark Thomas Avatar answered Jan 28 '26 03:01

Mark Thomas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!