java - 如何检查复选框是否已在编辑页面上选中
问题描述
根据场景,如果复选框已经被选中,那么我只需要打印文本,如果复选框没有被选中,那么我需要点击复选框。
//-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 元素。
解决方案
isSelected()
不适用于LABEL
标签,仅适用于INPUT
s。在INPUT
您发布的 HTML 中。
boolean sandboxClientCheckbox = driver.findElement(By.id("acChkSandboxClient")).isSelected();
推荐阅读
- ruby-on-rails - 了解“LoadError:无法自动加载常量”
- .net - FirebaseException:Javax.Net.Ssl.SSLPeerUnverifiedException 尝试从 Xamarin 应用程序连接到 Firebase 时
- javascript - index.js 不会触发 JS 文件中的函数单击 evt
- javascript - 我的网页上的暗模式按钮有问题。无论我做什么,它总是出错,就好像它是一个无限循环
- repeat - 如何在特定条件下重复状态图?
- r - 使用 sample_n() 函数替换采样权重
- python - 在 Python Dataframe 列中打印具有最大长度的字符串
- python - 有没有办法告诉(拦截)类属性的修改?
- xml - MarkLogic XDMP-COMPARE -- 不可比较的项目:xs:QName("foaf:OnlineAccount")
- mysql - Azure Linux VM 通过 TCP 响应缓慢