cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
prorokrak
Regular Visitor

set checkbox on web form - how to select correct one

Hi, first of all I would like to thank anybody willing to help me with my problem.

 

I need to fill a web form and there are a lot of records to add. Therefore I would like to automate the work.

I read the data from CSV file, and then need to populate the web form with retrieved data in loop.

The thing is that some fields are combo-boxes containing checkboxes. One such field is Country.

If I just populate country name to the appropriate textbox and then try to submit the form, I get an error that no country was selected. I actually have to check the corresponding checkbox.

 

This is how my flow looks like right now.

prorokrak_0-1638128966637.png

  1. It populates the country name to the text field. However, this step does not actually change anything. It does not check the checkbox of the country. Neither it scrolls the combo-box to the appropriate country. Thus, it is probably unnecessary.
  2. It clicks on the arrow to actually show the list of countries.
  3. It always checks the item that is on the top of the list.

This is what the selector chkPartiallyWorking looks like:

 

div[Id="ctl00_Body_GridView1_ctl00_ctl02_ctl03_Ins_RadCountry_rcbDBCBox_DropDown"]  ul[Class="rcbList"]  label > input[Class="rcbCheckBox"]

 

 

And this is screenshot from the browser.

prorokrak_2-1638129722980.png

 

Is it possible to check the correct checkbox with Power Automate Desktop? And how should selector look like? Or any alternative ideas how I can achieve what I need?

 

1 ACCEPTED SOLUTION

Accepted Solutions
VJR
Memorable Member
Memorable Member

Hi @prorokrak 

 

The action is used to interact with the elements on the webpage via javascript.

Some example videos on what/how it can do.

https://www.youtube.com/watch?v=mwCwmbdUcgA

https://www.youtube.com/watch?v=E-WE9BpneOM

 

The second screenshot in the post that is marked as an answer shows how the action is used to tick a checkbox element.

https://powerusers.microsoft.com/t5/Power-Automate-Desktop/Set-radio-button-checked-by-using-Run-Jav...

 

 

View solution in original post

10 REPLIES 10
Highboy
Skilled Sharer
Skilled Sharer

What happens if you click on the name in the list ?
This is a list item, and could possible be set by using

Highboy_1-1638130402555.png

 

prorokrak
Regular Visitor

When manually clicking on the label (country name text). it checks the item.

However, the "Set drop-down list" action does not work. I have tried two selectors:

 

This selector highlights with yellow topmost item (the whole row with the country Australia), even though I have chose Belgium. However, it does not check the checkbox.

 

div[Id="ctl00_Body_GridView1_ctl00_ctl02_ctl03_Ins_RadCountry_rcbDBCBox_DropDown"] > div[Class="rcbScroll rcbWidth"] > ul[Class="rcbList"]  label

 

 

This selector highlights with yellow all items in the list:

 

div[Id="ctl00_Body_GridView1_ctl00_ctl02_ctl03_Ins_RadCountry_rcbDBCBox_DropDown"] > div[Class="rcbScroll rcbWidth"]

 

 I have tried both Select options by name/by index but neither worked.

Do you have a link to the webpage or is it a company webpage?

VJR
Memorable Member
Memorable Member

Hi @prorokrak 

 

- There is a space at the end of the country names For eg; "AUSTRALIA ".

Hope you have considered that in whatever you have tried so far. If not, please redo the tests with the extra space.

 

- Another option is to use the "Run javascript function on webpage" action in PAD. Try and see if you can trigger the checkboxes using that.

 

It is a company webpage, login is necessary.

prorokrak
Regular Visitor


@VJR wrote:

Hi @prorokrak 

 

- There is a space at the end of the country names For eg; "AUSTRALIA ".

Hope you have considered that in whatever you have tried so far. If not, please redo the tests with the extra space.


Yes, I took the spaces into account. Actually, every country is right-padded with spaces to have the same number of characters. Therefore,

 

Australia is actually 
"AUSTRALIA           ", Belgium is actually 
"BELGIUM             "

 

That was also the reason why I tried to use indices.

 

The suggestion "Run javascript function on webpage" sounds interesting to me but I do not know what function I should run. Could you be more specific, please, how should I use it?

 

Thanks for your effort and time.

VJR
Memorable Member
Memorable Member

Hi @prorokrak 

 

The action is used to interact with the elements on the webpage via javascript.

Some example videos on what/how it can do.

https://www.youtube.com/watch?v=mwCwmbdUcgA

https://www.youtube.com/watch?v=E-WE9BpneOM

 

The second screenshot in the post that is marked as an answer shows how the action is used to tick a checkbox element.

https://powerusers.microsoft.com/t5/Power-Automate-Desktop/Set-radio-button-checked-by-using-Run-Jav...

 

 

prorokrak
Regular Visitor

Thank you for the interesting resources. I will try this approach and then get back to let you know how it went.

prorokrak
Regular Visitor

I have tried the JavaScript method but without success.

I have adjusted my flow like this:

prorokrak_0-1638203997568.png

My JavaScript code reads:

 

 

function ExecuteScript() { 
//Hard-coded a specific country for testing purposes
var checkbox = document.querySelector("#ctl00_Body_GridView1_ctl00_ctl02_ctl03_Ins_RadCountry_rcbDBCBox_DropDown > div > ul > li:nth-child(3) > label > input");
checkbox.checked = true;
checkbox.setAttribute("aria-checked", "true");
 }

 

 

 

Already the first action successfully checks the checkbox, as well as sets the attribute "aria-checked".

The other commands were more like to be on the safe side (show the combo box, populate text field with country name, hide the combo box).

Still, when I press Submit, I got an error "No country selected".

 

At first, I did not set the attribute "aria-checked" with JavaScript but I got the "No country selected" error. So I thought the attribute could make the difference but it did not.

 

I have no idea what else is going on there - why I have to click on the country to have the form accepting the country.

 

Any other suggestions what I could try?

prorokrak
Regular Visitor

Finally, I was able to solve it. There was another part of the page that was updated when clicking the combo box. It was tricky because it was at a different place in the html code.

prorokrak_0-1638210320242.png

I had to update these values as well in order to get the form working.

function ExecuteScript() { 
var checkbox = document.querySelector("#ctl00_Body_GridView1_ctl00_ctl02_ctl03_Ins_RadCountry_rcbDBCBox_DropDown > div > ul > li:nth-child(3) > label > input");
checkbox.checked = true;
checkbox.parentElement.parentElement.setAttribute("aria-checked", "true");

var setInput = document.querySelector("#ctl00_Body_GridView1_ctl00_ctl02_ctl03_Ins_RadCountry_rcbDBCBox_ClientState");
setInput.setAttribute("value", '{"logEntries":[],"value":"","text":"BELGIUM             ","enabled":true,"checkedIndices":[2],"checkedItemsTextOverflows":false}');
 }

Now I need to figure out how to make the JavaScript code dynamic.

But in the end, the JavaScript function was way to go.

 

Thank you for pointing me in the right direction.

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Users online (1,521)