views:

527

answers:

1

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']
+2  A: 

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

Rubens Farias
what about for select with multiple options ? how can you select more than one option ?
oiuqwyer
The first option by Rubens (shortened: `//select/option`) selects in fact all `option` tags. Also from other `select` tags, if you have more than one.
andre-r
its right, andre-r; returning one or several elements depends on SelectSingleNode/SelectNodes method usage
Rubens Farias
can one select the option by what is inside the tag? eg, not with the index, [1], but something like (unsuccessfully)//select/option[@label='1']
skyl
you can do `//select/option[. = '1']`
Rubens Farias