如何检查复选框是否已选中 [英] How To Check Checkbox Is Already Checked Or Not

查看:93
本文介绍了如何检查复选框是否已选中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据情况,如果复选框已被选中,那么我只需要打印文本,如果复选框未被选中,那么我需要单击复选框.

As per scenario if checkbox is already checked then i need to print only text and if check box is not checked then i need to click on checkbox.

//-Check sandbox test client checkbox is already checked or not if not then tick on checkbox
boolean sandboxClientCheckbox = driver.findElement(By.xpath("//div[@class='eplChkBoxWrapper']//label[@id='acChkSandboxClientForLbl']")).isSelected();       
System.out.println("Check checkbox value " +sandboxClientCheckbox);
if(sandboxClientCheckbox == true)   {
    Utils.pauseTestExecution(3);
    System.out.println("Checkbox is already checked  ");            
} else {
            driver.findElement(By.id("acChkSandboxClientForLbl")).click();
}  

当我打印复选框的值时,这表明是错误的.但是,第一次总是选中

When i am printing value of checkbox then this is showing false. But first time this is always checked

该复选框的HTML值为:

HTML values for checkbox is :

<div class="eplChkBoxWrapper">==$0
 <input type="checkbox" id="acChkSandboxClient" class="eplChkBox" checked>
<label id="acChkSandboxClientForLbl" for="acChkSandboxClient">
::after
</label>

任何人都可以帮助我,如何在执行时选中此复选框.我共享了DOM元素enter code here

Can anyone help me how i can check this checkbox is already checked or not at the time of execution . I have shared DOM elementes enter code here

推荐答案

您尝试过element.isEnabled()吗?如果是这样,请尝试使用getAttribute函数获取检查的属性.我认为如果取消选中该复选框,它将消失.

Did you try element.isEnabled()? if so try to get the attribute checked using getAttribute function. I think it gonna disappear when the checkbox is unchecked.

这篇关于如何检查复选框是否已选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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