isSelected()方法的checkbox总是返回false [英] isSelected() method for checkbox always returns false

查看:2105
本文介绍了isSelected()方法的checkbox总是返回false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有一个复选框,显示为已选中,现在当我检查时,它会以HTML中的图片src 显示。当我点击复选框,它被取消选中或选中。

There is a check box which is displaying as checked already, now when I inspect it shows with image src. in HTML. When I click on the checkbox, it is getting unchecked or checked.

为了验证它的状态,我写了这个代码, 。

To verify its state, I have written this code, which always brings false even though the checkbox is selected.

WebElement chBox = driver.findElement(By.xpath
     ("/html/body/div[3]/div[2]/form/fieldset/div[1]/table/tbody/tr[10]/td/img"));

        if (chBox.isSelected()) {
            System.out.println("User active check box is already checked");
        } else
            System.out.println("User active check box is not checked");
        }

为什么?

推荐答案

WebElement chBox = driver.findElement(By.id("chkIsActive"));

if (chBox.isSelected())
{
   System.out.println("User active check box is already checked");
} 

else
{
   System.out.println("User active check box is not checked");
}

希望这有助!

这篇关于isSelected()方法的checkbox总是返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆