Solved

How to search exact text on page, and then click the checkbox in its div

  • 18 February 2023
  • 3 replies
  • 395 views

Badge +4

On my webpage, I have a list of Departments. Each department has a checkbox, as you can see below:

I have an Excel file which has a subset list of Departments:

In RPA, I want to loop through each record (department) from Excel. Then, for each department, I want to search for the department on my webpage, and then click the checkbox to the right of it.


1. Start loop
2. Start first iteration
3. Search 46th & R Motor Vehicles on the webpage, then click the checkbox to the right of it
4. ...Do other actions and end first iteration...
5. Start second iteration
6. Search 605 Building, then click the checkbox to the right of it
7. ...Do other actions and end second iteration...
8. Start third iteration
9. Administrative Services, then click the checkbox to the right of it
10. ...Do other actions and end third iteration...
11. End loop

icon

Best answer by bradwyatt 22 February 2023, 05:05

View original

3 replies

Userlevel 7
Badge +13

Hi @bradwyatt ,

 

You can utilize the HTML property called HTML innerText or HTML Value to get the text from page through the Capture action. Once you have it, compare the same with the excel record using the IF condition. If they are matching, you can click the check box.

Badge +4

Hi @Padmakumar ,

Thanks for the suggestion.

I was able to use HTML innerText to extract all the text from the page’s div. Screenshot below for reference.

If I did a Recorder Capture and clicked the first checkbox, it would just check the first checkbox on the page each time I loop through the Excel records, but I want to be able to check the checkbox only for the matching Departments.  So how can I check the checkbox only on the matching Departments?

For reference, each element on the page has the following HTML:

<li class="drop-item"><div class="drop-item__bar no-children"><span class="drop-item__bar__icon__blank"></span><span class="drop-item__text" title="605 Building"><span>605 Building</span></span></div><div class="drop-item__buttons"><button role="checkbox" class="drop-item__checkbox js-node-checkbox" data-id="18d7b0bf-5eda-464a-885c-57302f5f7149"><span class="fonticon checkmark-icon"></span></button></div><ul class="drop-item__wrapper"></ul></li> 

 

Badge +4

I figured out how to solve what I was trying to do.

What I did, was I created a loop up to a specified number. For each iteration, I named the output variable $Counter$, and then I converted number to string and called it $CounterToString$.

Then, I did “Record: Capture” and I selected a checkbox on the page (it could be any of them). Then, under “Path”, I replaced what would have been the position of the checkbox on that page, with $CounterToString$.

The path:
1|1|-1|1|1|-1|1|1|-1|1|-1|-1|1|[$CounterToString$]|2|1
 

This also corresponded to the following DOMXPath:
//div[@id='main']/div[1]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[3]/ul[1]/li[$CounterToString$]/div[2]/button[1]

Reply