3
使用xpath,你如何选择第n个选项?xpath:如何选择第n个选项?
<select>
<option></option>
<option></option>
</select>
/HTML /体/选择/选项
使用xpath,你如何选择第n个选项?xpath:如何选择第n个选项?
<select>
<option></option>
<option></option>
</select>
/HTML /体/选择/选项
你有什么是正确的[?]:
的第二个选项,使用:
/html/body/select/option[2]
或
/html/body/select/option[position()=2]
请参阅http://www.w3.org/TR/xpath#location-paths
编辑
注意的是,上述假设你有如下的结构:
<html>
<body>
<select>
<option></option>
<option></option>
</select>
</body>
</html>
如果你的选择是比身体其他家长的里面,那么你要么需要使用这样的:
/html/body/div[@class='header']/select/option[2]
或
//select/option[2]
当然,由于您的选择可能具有名称属性,因此您可以使用该属性
//select[@name='myselect']/option[2]