Hi,
I am creating automation script for Regression testing. I got stuck in scenario where I have to click the ‘Dark Mode’ toggle button. I have to verify that toggle button is working as expected.
I tried following options
Click button
Click element
Select Checkbox
Get webelement
You testing the wrong element.
You try to see if element label is enabled, but you need to see the actual checkbox state, element input.
Furthermore, we have dedicated keywords for checkbox elements state. Just search docs ;).
Was that the first error you got, stale element not found ? You should have posted that in the first place.
Probably there are more elements with that XPATH, and Selenium is still trying to access the previous found one. You should try to focus on the element, and only the Get Webelement , you can use Mouse ... keywords for this.
You should confirm with browser dev tool (F12, then Ctrl-F) to see how many elements exist with that XPATH, then try to have a better locator. For example use the element type explicitly, like in //input[@id="mode-toggle-header"]