英文:
How to verify if a check box is checked when ::after gets added once check box is checked
问题
我正在尝试在Selenium代码中验证复选框是否被选中。复选框在被选中后会添加::after伪元素,但我无法验证该伪元素是否存在。有人能帮我解决这个问题吗?我无法找到一个正确的JavaScript代码片段。
(图片已省略)
英文:
I'm trying to verify whether a check box is checked or not in the selenium code. It gets added ::after once the checkbox is checked but I'm not able to verify that pseudo element exist or not. Can anybody please help me to resolve that issue? I was not able to find a correct JavaScript snippet for that.
答案1
得分: 0
你可以检查伪元素的属性。例如:
console.log(window.getComputedStyle(document.querySelector('h1'), '::after').getPropertyValue('content'));
<html>
<head>
<meta charset="UTF-8" />
<style>
h1::after {
content: "new";
}
</style>
</head>
<body>
<h1>site</h1>
</body>
</html>
英文:
You could check pseudo element properties properties. E.g.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
console.log(window.getComputedStyle(document.querySelector('h1'), '::after').getPropertyValue('content'));
<!-- language: lang-html -->
<html>
<head>
<meta charset="UTF-8" />
<style>
h1::after {
content: "new";
}
</style>
</head>
<body>
<h1>site</h1>
</body>
</html>
<!-- end snippet -->
答案2
得分: 0
你想要找到该元素并使用 isSelected。
isChecked = driver.findElement(By.xpath("label[class='labelContainer']/input")).isSelected();
英文:
You want to find the element and use isSelected.
isChecked = driver.findElement(By.xpath("label[class='labelContainer']/input")).isSelected();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论