Warm tip: This article is reproduced from serverfault.com, please click

How to verify toggle button is enabled or disabled in robot framework

发布于 2020-11-26 12:55:47

I have multiple settings which I need to enabled or disabled in test automation step. I am using python-robot-selenium. I dont want manual to reset requirements before running the script. When my toggle buttons are enabled or disabled the xpath is same for both so I am not able to handle it. Any other way to achieve it?

Below is the xpath and full xpath for both enabled and disabled status of toggle button

Xpath = //*[@id="tabTest"]/div[2]/div[2]/div[2]/label
Full xpath = /html/body/div[2]/div[2]/div[4]/div[1]/div[2]/div/div[1]/div[2]/div[2]/div[2]/label

Buttons and its inspect element is as below.

enter image description here

enter image description here

Questioner
Amaze_Rock
Viewed
0
Amaze_Rock 2020-12-02 11:33:41

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).

#Check the status of toggle button whether its enabled or disabled.
    ${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