# Validating toggle Switch button ON/Off

**URL:** <https://forum.robotframework.org/t/validating-toggle-switch-button-on-off/7267>\
**Category:** Robot Framework\
**Created:** [8 May 2024 10:41 UTC](https://forum.robotframework.org/t/validating-toggle-switch-button-on-off/7267 "2024-05-08T10:41:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kirti](https://avatars.discourse-cdn.com/v4/letter/k/ecccb3/32.png) [@kirti](https://forum.robotframework.org/u/kirti)\
**Post date:** [8 May 2024 10:41 UTC](https://forum.robotframework.org/t/validating-toggle-switch-button-on-off/7267/1 "2024-05-08T10:41:37Z")

</div>

Hi All,

I am not able to validate toggle switch button is ON or OFF.  
I have used “Element Attribute Value Should Be” but this is not working

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/3/362ffeb7dabb658838651848698dbd2fce565e70.png)

There are no color attributes.

Could you please help me.

Regards,  
Kirti Kori

---

<div class="post-metadata">

**Author:** ![CharlieScene](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/charliescene/32/3484_2.png) [@CharlieScene](https://forum.robotframework.org/u/CharlieScene)\
**Post date:** [8 May 2024 12:12 UTC](https://forum.robotframework.org/t/validating-toggle-switch-button-on-off/7267/2 "2024-05-08T12:12:24Z")

</div>

Hi,

These toggle button have usually no change in DOM attribute, nor in the css.  
But you can use _Checkbox Should (Not) Be Selected_, that will give you the results depending of the click.  
Here’s an exemple with w3 schools page (4th right-bottom toggle).

```
ToggleCheck
    Open Browser https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_switch chrome
    Maximize Browser Window
    VAR ${toggle_click} (//label[@class='switch'])[4]
    VAR ${toggle_button} (//label[@class='switch']//input)[4]

    Wait Until Element Is Visible //iframe[@id="iframeResult"]
    Select Frame //iframe[@id="iframeResult"]
    Wait Until Element Is Visible ${toggle_click}

    # Deactivate the toogle button and check status
    Click Element ${toggle_click}
    Checkbox Should Not Be Selected ${toggle_button}

    # Activate the toogle button and check status
    Click Element ${toggle_click}
    Checkbox Should Be Selected ${toggle_button}

```

Regards  
Charlie

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [8 May 2024 12:13 UTC](https://forum.robotframework.org/t/validating-toggle-switch-button-on-off/7267/3 "2024-05-08T12:13:23Z")

</div>

Hi Kirti,

your “toggle switch” is actually a stylised checkbox:

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/c/cf93fd352439dabbdd195bff2e10aca942451a46.png)

Checkbox’s are an unusual input because they don’t always have a value, but rather have an attribute `checked` that has no attribute value but rather if it’s there the checkbox is checked, and if it’s not there the checkbox is unchecked.

So try [Checkbox Should Be Selected](https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html#Checkbox%20Should%20Be%20Selected) or [Checkbox Should Not Be Selected](https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html#Checkbox%20Should%20Not%20Be%20Selected) on this input field.

Dave.

---

<div class="post-metadata">

**Author:** ![rasjani](https://avatars.discourse-cdn.com/v4/letter/r/858c86/32.png) [@rasjani](https://forum.robotframework.org/u/rasjani)\
**Post date:** [8 May 2024 12:54 UTC](https://forum.robotframework.org/t/validating-toggle-switch-button-on-off/7267/4 "2024-05-08T12:54:12Z")

</div>

I’d extend @damies13 's answer and tell your dev’s to populate the actual value into element.

I’m not 100% sure since its way too long since i’ve done actual fe development but the checkbox state is actually available for the frontend code even though the element in the dom is not updated in the dom when its toggled on or off.

For example and **afaik** on nextjs/react side, one has to explicitly implement state handling that updates the dom when toggled on/off. So, Imho, best option would be to talk to your devs to implement this for testability purposes.

PS. I might be wrong…
