如何检查复选框是否已在编辑页面上选中 [英] How to check Checkbox is already checked or not on edit page
本文介绍了如何检查复选框是否已在编辑页面上选中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
根据情况,如果复选框已被选中,那么我只需要打印文本,如果复选框未被选中,那么我需要单击复选框.
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();
}
HTML标记为
<div class="eplChkBoxWrapper">==$0
<input type="checkbox" id="acChkSandboxClient" class="eplChkBox">
<label id="acChkSandboxClientForLbl" for="acChkSandboxClient">
::after
</label>
有人可以帮助我吗?我如何检查此复选框在执行时是否已选中?我共享了DOM元素.
Can anyone help me? how I can check this checkbox is already checked or not at the time of execution ? I have shared DOM elements.
推荐答案
isSelected()
不适用于LABEL
标记,仅适用于INPUT
s. INPUT
在您发布的HTML中.
isSelected()
doesn't work on LABEL
tags, only INPUT
s. The INPUT
is in the HTML you posted.
boolean sandboxClientCheckbox = driver.findElement(By.id("acChkSandboxClient")).isSelected();
这篇关于如何检查复选框是否已在编辑页面上选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文