Xpath to determine checkbox “checked” attribute in Selenium IDE

只谈情不闲聊 提交于 2019-12-05 07:47:44

Here stnewrecord is class of check-box. Script will store number of check-box, and according to that loop will follow. It will check whether check-box is checked or not if not it will check else move to next step.

xpath=(//input[@class='stnewrecord'])[${i}]  

This is xpath of check-box. 'i' is position, it will increase on each iteration.

Let me know whether its working for you or not..

The xpath

// Xpath, only works in certain situations
//input[@type='checkbox' and @checked='xyz']

only works if in the HTML source of the checkbox there is an attribute as follows

checked="xyz"

where the developer is free to replace "xyz" with anything: "true", "checked", "ischecked", ...

So if there is no such attribute, the above mentioned xpath does not work.

While waiting for more insight, you might consider using a CSS selector, which does not depend on such an attribute:

// 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']

Note that without

[type='checkbox']

you will be given also radios :-)

However, there are solution without using css classes and selectors.

Use

//input[@type='checkbox' and @checked]

or

//input[@type='checkbox' and not(@checked)]

instead of

//input[@type='checkbox' and @checked='xyz']

something like this may works:

//input[@checked='checked']/following-sibling::*[1][not(@checked='checked')]

You can try these one:

//*[@type='radio'][@checked='checked']/
//*[@type='radio'][not(@checked='checked')]/
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!