Xpath确定Selenium IDE中的复选框"已检查"属性

sak*_*zai 6 selenium xpath selenium-ide

如何确定是否通过xpath检查复选框

目前我正在尝试:

//input[@type='checkbox' and @checked='true')]
Run Code Online (Sandbox Code Playgroud)

我有多个具有相同ID的复选框,因此我必须选择未选中/选中的下一个复选框.

具体来说,我需要这个用于Selenium IDE

编辑 我真正需要的东西......

|storeXpathCount | //input[@name='xyz' and @checked='checked'] | is_checked | 
Run Code Online (Sandbox Code Playgroud)

如果选中复选框'xyz',则is_checked值应为1,否则为0

谢谢

Cuo*_*yTo 9

xpath

// Xpath, only works in certain situations
//input[@type='checkbox' and @checked='xyz']
Run Code Online (Sandbox Code Playgroud)

只有在复选框的HTML源代码中才有效,如下所示

checked="xyz"
Run Code Online (Sandbox Code Playgroud)

开发商可以自由地用"xyz"代替任何东西:"true","checked","ischecked",......

因此,如果没有这样的属性,上面提到的xpath不起作用.

在等待更多洞察时,您可以考虑使用CSS选择器,它不依赖于这样的属性:

// CSS selector, for all checkboxes which are checked
input:checked[type='checkbox']

// CSS selector, for all checkboxes which are not checked
input:not(:checked)[type='checkbox']
Run Code Online (Sandbox Code Playgroud)

请注意,没有

[type='checkbox']
Run Code Online (Sandbox Code Playgroud)

你也会得到收音机:-)


Roh*_*are 4

在此输入图像描述

stnewrecord是复选框的类。脚本将存储复选框的数量,并根据该循环进行操作。它将检查复选框是否被选中,如果没有,它将检查,否则移至下一步。

xpath=(//input[@class='stnewrecord'])[${i}]  
Run Code Online (Sandbox Code Playgroud)

这是复选框的 xpath。“i”是位置,它会在每次迭代时增加。

让我知道它是否适合你。