我正在尝试验证是否选中了单选按钮。我有下面的单选按钮html代码片段。
<span class="jquery-hp-radio jquery-hp-radio-checked" style="-moz-user-select: none;">
<span class="mark">
<img src="http://someurl/images/empty.gif">
</span>
</span>使用以下代码进行了尝试-
if(driver.findElement(By.className("mark")).isSelected()){
System.out.println("True");
}else
{
System.out.println("False");
}
}它给出的输出为False -即使单选按钮在默认情况下处于选中状态。
发布于 2015-04-13 14:07:07
感谢@ Rameshwar
您的解决方案起作用了
我能够检测到单选按钮是否已选中或未选中"jquery-hp-radio jquery-hp-radio-checked" by
if(driver.findElement(By.xpath("//span[@class='mark']/..")).getAttribute("class").contains("checked")){
System.out.println("True");
}else
{
System.out.println("False");
}
}发布于 2015-04-10 17:33:20
我相信当你的单选按钮被选中时,它的class是jquery-hp-radio jquery-hp-radio-checked。
因此,您可以执行以下操作来检查是否选中了该按钮
if(driver.findElement(By.xpath("//span[@class='mark']/..")).getAttribute("class").contains("checked")){
System.out.println("True");
}else
{
System.out.println("False");
}
}发布于 2017-11-25 12:22:34
如果在应用程序中默认选择了单选按钮,则使用get attribute()。
例如:
if (driver.findelement(By.xpath ()).getattribute("componentid").endwith("true")){
system.out.println("selected")
}else{
system.out.println("not selected")
}https://stackoverflow.com/questions/29555974
复制相似问题