xml - 来自选择框的 XML 过滤器
解决方案
这是一个静态下拉列表,值不会改变。
请用
//option[@value='1' and @selected]
另外,你可以使用
//option[@value='1' and @selected and text()='B3']
PS:如果我们有唯一的条目,请检查dev tools
(谷歌浏览器)。HTML DOM
检查步骤:
Press F12 in Chrome
-> 转到element
部分 -> 执行CTRL + F
-> 然后粘贴xpath
并查看,如果您想要element
的是否使用匹配节点突出显示。1/1
更新 :
List<WebElement> dropDown = driver.findElements(By.xpath("//select[@name='wert_1']//option");
try{
for (WebElement option : dropDown)
if (option.getAttribute('selected').contains('selected')){
System.out.println("Selected option is "+ option.getAttribute('innerText'))
}
else
System.out.println("none of the options are selected")
catch(Exception e){
System.out.println("something went wrong")
}
推荐阅读
- java - 春季测试抛出 ResourceAccessException
- c# - 是否可以在 C# Interactive 上使用 Immutable.Collections?
- spring-boot - 从空列返回实体后出现空指针异常
- javascript - Nuxtjs 头部标题没有改变
- android-management-api - Android 管理不起作用,但它注册了设备
- hibernate - 用于检查字符串列的可能值集的注释 - Hibernate JPA
- python - 他们为什么不匹配?Python,created_at 至今
- elasticsearch - top_hits 类型的聚合器不能接受子聚合
- javascript - 在我自己的服务器上拥有 firestore 需要额外请求才能访问我的数据
- python-3.x - awk 未在 csv 文件中打印完整的列值