Support Portal

for ProcessRobot and WinAutomation

Start a new topic
Answered

How can a process select a checkbox based on label?

On a site where there are multiple checkboxes, whose ordering, amount, and IDs are often changing, how can a process select a checkbox based on the text in the label?  


Best Answer

I'm thinking


tr:contains("Honda")  input[type="checkbox"]

OR

tr:contains("Honda") > td > input[type="checkbox"]

 will probably work for you.


Could you paste some markup example and a couple of variations?

 Here is some code. In this example, there are two options "Honda" and "Toyota".  All of the IDs can change (rules out a ID selector) and also the order of the checkboxes change randomly (this rules out sending a certain number of tabs).  


What is needed is for this process to read "Honda" and then check the corresponding checkbox.  


<tr>
        <td class="abCheckbox"><input name="panel:rolesPanel:roleCheckGroup" type="checkbox" class="roleCB wicket-id22" id="id33" value="check97"/></td>
         <td>Honda</td>
         <td></td>
</tr>
<tr>
        <td class="abCheckbox"><input name="panel:rolesPanel:roleCheckGroup" type="checkbox" class="roleCB wicket-id34" id="id53" value="check97"/></td>
         <td>Toyota</td>
         <td></td>
</tr> 

  

Well, the solution could be a bit tricky.. lets see.


When there is no markup, usually I go for the block and I parse the text where the checkboxes are located.


In your case, only the brand is enclosed on <td> tags, other are empty.


If you parse the text with (?<=<td>).*(?=</td>)


winautomation will grab only two words, Honda and Toyota. You can keep them on a list.


After this you can easily Set Checkbox State on Web Page action, and create the proper selector with a variable, like this one:


html > body > input:eq(%mychoice%)


the input:eq(0) will select the FIRST checkbox, and input:eq(1) the SECOND checkbox.


This could be an approach. I hope it helps.


I can help you on the field if you want to share me the full url, but I think this could work on your case.

:Have you tried adding to end of checkbox selector the jquery selector: :contains('Honda')

Answer

I'm thinking


tr:contains("Honda")  input[type="checkbox"]

OR

tr:contains("Honda") > td > input[type="checkbox"]

 will probably work for you.

Login or Signup to post a comment