xpath for selecting

2019-06-16 01:13发布

问题:

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']

回答1:

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



回答2:

Another option:

//select[@id='id']/option[text() = 'option text']