Validation of toggle switch button ON or OFF

Hi All,

I am not able to validate toggle switch button is ON or OFF.
I have used “Element Should Be Disabled” & “Element Should Not Be Visible” but these are not working.

There are no color attributes.

Could you please help me.

Sneha Banad

this is the button is in grey color when it is off

That element is just a made to look like toggle button. Value is probably in the attribute “aria-checked”, on selenium most likely you can fetch the value via Get Element Attribute, with browser library, i dont know.

Why “Element Should Be Disabled” doesn’t work ? Because the element is not disabled. Disabled means that the element has “disabled” attribute. It essentially means that the element in question cannot be interacted with. Same with Element should not be visible. Toggling that element does not toggle its visibility, just the “aria-checked” attribute changes (most likely)


Hi Sneha,

In your screenshot you’ve highlighted a \<span> within a \<label>, above the \<label> is a \<input> element, this is the actual field you probably want. You could try with Checkbox Should Be Selected on that \<input> and the other related checkbox keywords

The for attribute on the \<label> will give you the id of the input if it’s dynamic and keeps changing

Hope that helps,


I need to test button is disabled so i used checkbox should not be selected but it failed.

Checkbox Should Not Be Selected //*[@id=“preference-center-myCommunications-content”]/div[1]/div[2]/div/label/span

error: Checkbox with locator ‘//*[@id=“preference-center-myCommunications-content”]/div[1]/div[2]/div/label/span’ not found.

If i used input elements then also it is failing.
getting error as: xpath not visible after 5 seconds

Yes rasjani,

It worked when i used Element Attribute Value Should Be aria-checked.