How to read on/off switch and change result respectively

Hi UiPathers,

I want to identify if this button is set to YES or No, then do the following actions.

If YES > switch button to NO

If NO > do nothing.

I tried get text and get attribute but neither work with this particular onoff switch. How can I capture this data? I have attached the respective code fore reference.

Thanks in advance,

for a simple solution, try using find image.
find image of No Selected.
And use if activity to proceed further.

As your switch is a html tag and not an image, you can check for the attribute(Get attribute activity) of the html tag that gets changed when you turn on/off.

Before that use UiExplorer or Browser inspector to see what value in the html tag gets changed.
Note: Based on the screenshot, I think its the class name which gets changed when you turn on or off. But can’t confirm without inspecting.


just explore in UiExplorer the checked attribute for following highlighted element

this should toggle according the on off status

Thank you everyone!
I tried Get Attribute with the attribute being:

  • “data-swchon-text”
  • “data-swchoff-text”
  • “data-swchon-text”

For all of them, the value came out blank. Any other ideas?

1 Like

Did you checked with Get Text activity

Yes I tried Get Text, and then a Message Box with the output and it was blank.

all depends on the implementation of the onoff switch. so if you can tell us (like Bootstrap…) or share a link would be great.

What you can do as well:

  • click the onoff switch to on
  • share a screenshot from uiexplorer with fully expanded property explorer on the selected input element (see my screenshot from above)

this would be helpfully for next analyises. Thanks

You could also use Get OCR Text to get if it is showing YES or NO… But only if no attributes can be used to determine the value chosen there (angular driven websites can be a pain)…

@eonofrey If the Problem is not Solved yet, Can you please post the Screenshot of the Selector in UiExplorer using a Click Activity , In that way We may Identify an Attribute that can get you the Value.


But the circle is dynamic and changes if set to YES or NO

@eonofrey Is this the Selector when it is Showing “Yes” , If So, Can you Also show us the Selector when it is Showing “No”

The previous one was NO, this one is YES

@eonofrey I cannot find any attribute which can tell us the State of the Button :sweat_smile:, I guess you need to use Get OCR Text and Find out if it is Able to Extract the Value.

compared with other onoffswitch implementation we can excpect with higher proabability the yes/no toggled info on the input(check) html element.

Please share this info as requested above with us. Thanks

1 Like

You should look in there (scroll down) and look for differences (if any) from the 2 states of the control:

1 Like

So I think its chkPrimaryTenant, but I dont see it on the right side

have a check on get attribute on the checked attribute (the input element). this schould toogle similar to on off (see my post from above with highlighted screenshot)

if you have the input type and it has checked=1 or 0, then you definitely should use it in the selector.