xpath for selecting

2019-06-16 00:51发布

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条回答
Fickle 薄情
2楼-- · 2019-06-16 01:24

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

查看更多
祖国的老花朵
3楼-- · 2019-06-16 01:34

Another option:

//select[@id='id']/option[text() = 'option text']
查看更多
登录 后发表回答