问题
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']
来源:https://stackoverflow.com/questions/1535377/xpath-for-selecting-option-html-tag