我想指定我的网页元素的 xpath。
<select id=groupSelect>
<option value="data" >First value</option>
<option value="data" >second value</option>
</select>
我想获得“第一个值”,它是选项内的文本。但我不知道如何获取文本。
By.xpath("//select[@id='groupSelect']/option[@value=???']"))
selenium
can handle select/option https://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/support/ui/Select.html以一种美好而方便的方式。
以下是如何通过可见文本选择选项(Java 中的示例):
Select select = new Select(driver.findElement(By.id("groupSelect")));
select.selectByVisibleText('First value');
如果您仍然想要基于 xpath 的解决方案,您可以选中该选项value
和text
:
By.xpath("//select[@id='groupSelect']/option[@value='data' and . = 'First value']")
或者通过索引获取:
By.xpath("//select[@id='groupSelect']/option[1]")
或者您可以同时检查两者。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)