用于选择<option> html标签的xpath?</option>

时间:2009-10-08 02:57:02

标签: xpath nokogiri

用于选择html标签的xpath?

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

下面会不够?

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

2 个答案:

答案 0 :(得分:14)

这里有几个选项:

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

所有这些导致第一个选项元素

答案 1 :(得分:6)

另一种选择:

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