最佳答案
您可以使用以下代码来检查选项是否启用或禁用。尝试使用下面的代码。
WebElement selectDropDown=driver.findElement(By.xpath(".//select[@id='level_points']"));
List<WebElement> options=selectDropDown.findElements(By.tagName("option"));
for(int i=0;i<options.size();i++)
{
try{
String isDisabled=options.get(i).getAttribute("disabled");
//Write the required code if disabled
}
catch(Exception ex)
{
//Write required code if not disabled
}
}
我的机器上没有Eclipse,所以如果有语法错误,请注意。 您将在 try block 中获得所有禁用的选项,因为您具有该属性,并且在 catch block 中您将获得未禁用的选项。
关于java - 如何使用 WebDriver 验证下拉菜单的启用禁用值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46701715/