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
There are no color attributes.
Could you please help me.
Regards,
Kirti Kori
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
There are no color attributes.
Could you please help me.
Regards,
Kirti Kori
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
Hi Kirti,
your “toggle switch” is actually a stylised checkbox:
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 or Checkbox Should Not Be Selected on this input field.
Dave.
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…