Posted: 18 Mar 2021 20:58 EDT Last activity: 31 Mar 2021 14:42 EDT
Select checkbox from drop down list on a web page based on a parameter
I am trying to select a check box from a drop-down list on a web page. I am able to select the button to open the list but I can not seem to select the checkbox in the drop-down list. Sometimes there will be more than one option in the list, so I will not always be selecting the first item in the list. I need to select the option from the drop-down list that matches my parameter for this report. Any suggestions on how I can 1. select the check box and 2. loop through the drop-down options and match based on a parameter for this report? Would I need to use a list loop to loop through the drop-down list and then compare each item to my parameter and then select the check box if there was a match? I have tried to use ExecuteScript based on the onclick value for the check box and that did not work. I also tried to inspect the drop-down list using the select element and then perform the click and that did not work either.
***Edited by Moderator: Pooja Gadige to add platform capability tag***
If you can, post the InnerHTML of one of the parent controls (something up in the hierarchy you know would contain the checkbox control) and I can try to make a suggestion off of that.
@ZachT124 It looks like you need to create a match rule that will apply to all instances of the "checkbox" and set the UseKeys property to true. You can then use the GetClones method of that control to iterate through all of the instances. From the InnerHTML you've sent, it looks like raising the OnClick event will select the check box. That is how I would tackle this.
I have the value to select from the check box stored as a Global string variable that I am getting from an excel file. For this instance I am just passing a static value to select. I set the useKey to True for the list and the checkbox. I am not sure how to see the output from the listloop. What I am missing here?
Posted: 1 month ago
Updated: 1 month ago
Posted: 30 Mar 2021 11:25 EDT Updated: 31 Mar 2021 14:42 EDT
@ThomasSasnett Can you please assist me with this? I am getting the names from the checkbox list and I set usekeys = true. I have verified that the string that I am seeking is the same as the one from the list. But every time the listloop runs it timesout as there is not a match. What am I doing wrong for the match? And then I am still confused on how it will select the proper checkbox.
Posted: 1 month ago
Updated: 1 month ago
Posted: 30 Mar 2021 11:50 EDT Updated: 31 Mar 2021 14:42 EDT
@ZachT124 It doesn't appear that you are waiting for anything after you call PerformClick on btnAccounts. Is that what is loading the list? If so, you'll likely need at least a pause there to allow the clones to get created. A pause may be acceptable if that list always loads in a short amount of time. For testing though, I would make it twice whatever time it takes and test it several times to ensure you have all of them matched before you proceed.
Waiting for clones can be a little tricky since there isn't really one thing to wait on. I generally wait for a list of clones by looping with a brief pause in between.
Call GetClones and extract a proxy from the result.
Grab the count property of the proxy and record this into an Integer variable.
Start a ForLoop whose limit you will set based on how long you want this process to take before returning a failure.
Out of the forLoop, call a pause for N ms. Your limit of the loop with be the total number of seconds you want to wait divided by your pause duration converted to seconds (so if you are pausing for 500 ms and you want to wait 10 seconds, you'd set your limit to 20 - 10/0.5).
After the pause call GetClones again and extract a proxy.
Compare the current count to the previous one and if they match, break the loop and continue.
If they do not match, update the previous count to be equal to the current one and allow the loop to continue where it will first pause before checking again.
If your loop completes, it means that your list is still being populated or perhaps something went wrong. If you break out of the loop, it means you detected that after some period, the count remained stable and you can assume the list is fully loaded.
You can add additional logic here as needed. I often add a counter to make sure that the two counts match more than once before I continue, but that may not be required for every case.
@ThomasSasnett I implemented the forLoop to make sure the counts matched and they do. However, I am still not even able to get the strings to match. I am not sure what I am doing wrong. The two strings are exactly the same. I am getting three items in my list. The first item is the same as the string that I am trying to match. I have used the string Contains and a Boolean expression that I changed to string and ran that through a decision. Even if I get the strings to match how is the checkbox going to know which one to check? The video online shows that match rules on the checkbox, my match rules are not on the check box. I have attached some screenshots of my match rules. Any suggestions?
@ZachT124 It may be extra spaces in your strings or other hidden whitespace. You might try adding a Trim() and a ToUpper() to your boolean expression for each input; A.Trim().ToUpper()==B.Trim().ToUpper()
You might need to look into the RuntimeLog to see what the strings are coming in as. That would preserve whitespace there and you can see if they don't match.
@ThomasSasnett I am not sure why but when I took the text from the match rules and added it to my string variable in my excel file it matched and checked the box. The values visually appear to be the same, so I am not really sure why that fixed it. I had to paste the value from Pega match rules into my spreadsheet. I also was not using the proxy property which is why it was not checking the box.