Question
Transplace
US
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.
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accepted Solution
Updated: 31 Mar 2021 14:42 EDT
Pegasystems Inc.
US
@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.
@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.
Pegasystems Inc.
US
@ZachT124 I suspect you'll need to examine the inner HTML of that control. It is not being presented as a check box (input type=checkbox) so it is coming up as a generic control. You might need to select the checkbox using JavaScript. One thing you can try; go to the Web Controls tab and filter for check boxes. See if that control is actually present. Sometimes they are hidden behind others and you can still select them from that tab, but cannot interrogate directly.
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.
Transplace
US
@ThomasSasnett Here are a few screenshots of the innerHTML. One from the inspect menu and one from PEGA interragation.
Updated: 25 Mar 2021 10:36 EDT
Pegasystems Inc.
US
@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.
Transplace
US
@ThomasSasnett Thank you!
Pegasystems Inc.
US
Hey @ZachT124!
If @ThomasSasnett's reply resolved this for you, please click the ellipses and choose Accepted Solution to mark this as solved. That will help others in the future who may have the same question!
Thanks for your engagement today!
Transplace
US
@ThomasSasnett I have been trying to follow this example and I can not seem to figure out how this exactly works...
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?
Updated: 31 Mar 2021 14:42 EDT
Transplace
US
@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.
Accepted Solution
Updated: 31 Mar 2021 14:42 EDT
Pegasystems Inc.
US
@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.
@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.
Transplace
US
@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?
Transplace
US
@ZachT124 Here are the images from the results showing the values of my Boolean expression. I made sure I set the identifiers to string. I am not sure why I am not getting a True result
Pegasystems Inc.
US
@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.
Transplace
US
@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.