这是所选单选按钮的 html 代码
<input name="blooms_level" value="4" id="blooms_level4" class="radio " checked="" type="radio">
我尝试了下面的代码,它返回 null
String str = driver.findElement(By.xpath("xpathValue")).getAttribute("checked");
str.equalsIgnoreCase("true");
请建议任何替代方法,因为检查的值为空
最佳答案
尝试下面提到的 Java 代码:
Boolean radioSelected= driver.findElement(By.xpath("xpathValue")).isSelected();
if (radioSelected)
{
System.out.println("Radio Button is selected");
}else{
System.out.println("Radio Button is not selected");
}
关于java - 如何根据提供的 HTML 验证单选按钮是否被选中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51632054/