How to check radio button using JavaScript - Inject JS

uiautomation
studio

#1

Hello -

I have two radio button below and i need to check the option containing.

Radio Button

I can use click activity to perform this task but i wanted to try using Javascript (Inject JS activity ).

Please help me with the JS Code if the tag for clicking the “containing” radio button would be below

<INPUT type=radio value=containing name=selSearchField ></Input>


#2

YThis should work
Call below js file in injectjs activity

function check() 
{
 if(document.readyState === "complete") 
 {
    document.getElementsByName("selSearchField").checked = true;
  }
}

Or since it is a list try this ( did not test)

function check() 
{
 if(document.readyState === "complete") 
 {
    document.getElementsByName("selSearchField")[1].checked = true;
  }
}

#3

Thanks Vinay. Your second option worked like a charm. Also why use [1] ? i wanted to learn how it works.


#4

The radio buttons in the radiobutton list are index based, since your “containing” is the second item so the index value is 1 (starts from 0)


#5

Hello Vinay,

Thanks for all help so far. Just like how you used index, suppose there was a multi select list and i wanted to select two items, then how would i write the code ?

There is a issue with multi select activity in UiPath. It doesn’t work for me. Maybe i need to use Inject JS for my kinda issue ?

https://forum.uipath.com/t/select-multiple-items/