xpath for selecting <option> html tag?

user186084 picture user186084 · Oct 8, 2009 · Viewed 22.3k times · Source

xpath for selecting html tag ?

<select>
<option value="first option"> 1 </option>
<option value="second option"> 2 </option>
<option value="third option"> 3 </option>
</select>

Would below suffice ?

html/body/form/select[@name='options' and @value='first option']

Answer

Rubens Farias picture Rubens Farias · Oct 8, 2009

Several options here:

  • /html/body/form/select/option
  • /html/body/form/select/option[1]
  • /html/body/form/select/option[position() = 1]
  • /html/body/form/select/option[@value='first option']

All these lead to first option element