How to automate Toggle On/Off button by Selenium Java?

My best guess is to use relative locators, a feature of Selenium 4.
The first toggle button would be found like the button below the assigned label.
The second toggle button would be found like the button below the first toggle button.
Etc.

Some useful links are:

There might be other things to consider using these toggle buttons. If you are interested. then I can explain more.

2 Likes