gpt4 book ai didi

selenium - 如何使用 Selenium 检查复选框样式的输入范围是否已选中? Only::after 作为状态之间的区别

转载 作者:行者123 更新时间:2023-12-02 21:33:39 24 4
gpt4 key购买 nike

我正在尝试检查是否选中了复选框。我的复选框使用输入和跨度设置样式,不使用复选框标记。由于它不是默认复选框,我无法使用方法,例如isSelected或isChecked来检查其状态。然后我试图检查是否有任何类属于一个州而不属于另一个州。然而,到目前为止我发现的唯一区别是,当选择该元素时,会出现 ::after ,但不确定如何检查它?

我发现了一个有类似问题的教程,但对 Javascript 不太了解,也不知道如何使其适应我的情况。

https://www.quora.com/How-do-I-locate-After-and-Before-css-tag-in-selenium-webdriver

点击之前 enter image description here

点击后 enter image description here

这就是正在使用的内容,按照 @pguardiario 的回答

 System.out.println(js.executeScript("return window.getComputedStyle(document.querySelector('.custom-checkmark'), ':after').getPropertyValue('content')"));

但是无论选择与否,它都会返回相同的输出(空字符串)

更新

发现选中状态和未选中状态之间的区别。当未选中复选框时,.custom-checkmark:after 样式具有 display-none。仍然不确定如何使用此信息,因为这就是我目前所拥有的信息,并且在单击复选框之前和之后它们都返回不显示。

@Test
public void testingCheckbox() {

JavascriptExecutor js = (JavascriptExecutor) wd;

System.out.println(js.executeScript("return window.getComputedStyle(document.querySelector('.custom-checkmark'), ':after').getPropertyValue('display')"));

lp.clickCheckBox();

System.out.println(js.executeScript("return window.getComputedStyle(document.querySelector('.custom-checkmark'), ':after').getPropertyValue('display')"));
}

enter image description here

新发现

看起来实际上有“两个复选框”。一个带有 span 标签,另一个带有 span。当取消选择某些属性时,它们会一起出现。

enter image description here

感谢您的帮助。

最佳答案

我无法测试它,但它应该看起来像这样:

driver.executeScript('return window.getComputedStyle(document.querySelector(".custom-checkmark"), ":after").getPropertyValue("content")')

抱歉,顺便说一句,Java 没有heredocs,这让这很痛苦:(

关于selenium - 如何使用 Selenium 检查复选框样式的输入范围是否已选中? Only::after 作为状态之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57550257/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com