# How to test toggle button status?

**URL:** <https://forum.robotframework.org/t/how-to-test-toggle-button-status/1016>\
**Category:** Robot Framework\
**Created:** [26 November 2020 05:32 UTC](https://forum.robotframework.org/t/how-to-test-toggle-button-status/1016 "2020-11-26T05:32:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![adskul](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@adskul](https://forum.robotframework.org/u/adskul)\
**Post date:** [26 November 2020 05:32 UTC](https://forum.robotframework.org/t/how-to-test-toggle-button-status/1016/1 "2020-11-26T05:32:57Z")

</div>

Hi,  
I am stuck at one scenario.  
I want to test the on / off or in other words Enabled / Disabled status of toggle button in my web application using robot framework. In both of / off status I am getting same web element so it is getting hard to handle it. Any solution? I am using robot framework / Python / Selenium.

![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/1X/7d5c375f6beab4849ed88d82e000d689e7a9a743.png)

Thanks.

---

<div class="post-metadata">

**Author:** ![zastress](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/zastress/32/1259_2.png) [@zastress](https://forum.robotframework.org/u/zastress)\
**Post date:** [26 November 2020 07:23 UTC](https://forum.robotframework.org/t/how-to-test-toggle-button-status/1016/2 "2020-11-26T07:23:41Z")

</div>

Do you have the HTML corresponding to that element when it is on or off?

---

<div class="post-metadata">

**Author:** ![adskul](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@adskul](https://forum.robotframework.org/u/adskul)\
**Post date:** [26 November 2020 08:05 UTC](https://forum.robotframework.org/t/how-to-test-toggle-button-status/1016/3 "2020-11-26T08:05:01Z")

</div>

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

Above is the inspect element result

Below are Xpath and full xpath which is same when toggle is enabled or disabled.  
//\*[@id=“tabTest”]/div[2]/div[2]/div[2]/label  
/html/body/div[2]/div[2]/div[4]/div[1]/div[2]/div/div[1]/div[2]/div[2]/div[2]/label

---

<div class="post-metadata">

**Author:** ![zastress](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/zastress/32/1259_2.png) [@zastress](https://forum.robotframework.org/u/zastress)\
**Post date:** [26 November 2020 11:03 UTC](https://forum.robotframework.org/t/how-to-test-toggle-button-status/1016/4 "2020-11-26T11:03:12Z")

</div>

Maybe you could have taken a html screenshot for 2 buttons (one on and one off) so we could check for differences.  
BTW, that xpath is awfull, it is not at all reliable.

---

<div class="post-metadata">

**Author:** ![adskul](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@adskul](https://forum.robotframework.org/u/adskul)\
**Post date:** [26 November 2020 12:26 UTC](https://forum.robotframework.org/t/how-to-test-toggle-button-status/1016/5 "2020-11-26T12:26:45Z")

</div>

Which screenshot you want me to take exactly in html?

I tried below but not working

{style}= Get Element Attribute xpath=//\*[@id="tabtest"]/div[2]/div[1]/div[2]/label/span background-color {style} {bgcolor} Split String {style} background-color:  
log {style} log {bgcolor}

---

<div class="post-metadata">

**Author:** ![adskul](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@adskul](https://forum.robotframework.org/u/adskul)\
**Post date:** [2 December 2020 03:34 UTC](https://forum.robotframework.org/t/how-to-test-toggle-button-status/1016/6 "2020-12-02T03:34:39Z")

</div>

Below code is worked for me for me to get background color of toggle button. It will helpful to take the action based on **toggle button** **enabled(Green in color)** and **disabled(Grey in color)**.

```python
 ${BG} Get WebElement xpath=(//span[@class="slider round"])[3]
    ${bg color} Call Method ${BG} value_of_css_property background-color
    Run Keyword If '${bg color}' == 'rgba(204, 204, 204, 1)'
    ... Click Element xpath=(//span[@class="slider round"])[3]
    ... ELSE
    ... Click Element xpath=//*[@id="app"]/div[2]/div[4]/div[1]/div[1]/div/div/ul/li[2]/a

```

---

<div class="post-metadata">

**Author:** ![rakesh](https://avatars.discourse-cdn.com/v4/letter/r/258eb7/32.png) [@rakesh](https://forum.robotframework.org/u/rakesh)\
**Post date:** [18 July 2022 19:43 UTC](https://forum.robotframework.org/t/how-to-test-toggle-button-status/1016/7 "2022-07-18T19:43:53Z")

</div>

I have also used the same code in my test case template but I am getting the bellow error:

Evaluating expression ‘rgba(0, 0, 0, 0.25) == rgba(0,0,0,.25)’ failed: NameError: name ‘rgba’ is not defined nor importable as module

---

<div class="post-metadata">

**Author:** ![rakesh](https://avatars.discourse-cdn.com/v4/letter/r/258eb7/32.png) [@rakesh](https://forum.robotframework.org/u/rakesh)\
**Post date:** [18 July 2022 19:44 UTC](https://forum.robotframework.org/t/how-to-test-toggle-button-status/1016/8 "2022-07-18T19:44:41Z")

</div>

I have used the above code but I am getting the below error:

Evaluating expression ‘rgba(0, 0, 0, 0.25) == rgba(0,0,0,.25)’ failed: NameError: name ‘rgba’ is not defined nor importable as module
