AnOldSoul
AnOldSoul

Reputation: 4207

How to locate the checkboxes with the attribute checked

I have a list of checkboxes and I need to find the checkboxes that have the attribute "checked". Below is how my check box element looks,

<input type="checkbox" class="u-display--inline-block u-margin-right--small" checked="">

How can I find this with xpath? I cannot use //input[@type='checkbox' and @checked='true')] because i don't have a checked value true attribute. Any advice would be much appreciated.

Upvotes: 0

Views: 1199

Answers (3)

Bhavesh Soni
Bhavesh Soni

Reputation: 198

Kindly use below xpath for the same:

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

Upvotes: 1

undetected Selenium
undetected Selenium

Reputation: 193108

To find the checkboxes that have the attribute checked you can use either of the following solutions:

  • cssSelector:

    "input.u-display--inline-block.u-margin-right--small[type='checkbox'][checked]"
    
  • xpath:

    "//input[@class='u-display--inline-block u-margin-right--small' and @type='checkbox'][@checked]"
    

Upvotes: 1

har07
har07

Reputation: 89295

You can just mention the attribute checked to test if it exists:

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

Upvotes: 1

Related Questions