How to iterate a select

I want to iterate through the options of a select. I have managed to create a selector (with GetElement) that highlights the dropdown but I am struggling to find out how to iterate over the options, ignoring some and doing further workflow on others.

I have found a post that mentions that the options are in item.items but how do access them? I have looked at For Each Datarow and For Each <> (also called ForEachOf) but in the template “For each [item] in [ X]” the X is a long list of names that mean almost nothing to me (OK, “Exit” means something but not as something to iterate over!). However, perhaps the list of names is OpenRPS just being helpful … it will accept “items” but then complains it is not declared.

How do I use item.items to access the options? And the value attribute and data of each?

Is there any documentation for all these facilities? Nothing I have so far found has the detail I need.

Use ForEachOf
In type Argument type, select string
The use


Thank you for your reply. However, it hasn’t moved me forward, since I just get the error message “Item is not declared” and by tweaking the identifiers I have determine it is the identifier “item” in the right hand box it is referring to.

More fundamentally would it be possible to explain how this string (in the right hand box) works? Unfortunately I have never used VB which seems to be a significant hurdle … I am not even sure which dialect of VB OpenRPA uses. I am guessing that “function(x)” is an anonymous function (my terminology), which is passed to Select which invokes it with an object that has an attribute “name” which the function returns. However, I can find no documention that indicates that this is VB. However, <lightbulb> it could be Javascript which would tie in with other posts I have read. But in experimenting with what goes in the right hand box I have been getting VB errors, so I am still very confused!

The prototype for ForEachOf indicates the right hand box is a “ConditionalDescription” but this means absolutely nothing to me.

You get an element using Get element and you then perform actions with the element using item inside the Get element
If you are getting an error item does not exsits, my guess is, you did not place the ForEah inside the body of an Get element.

I’m not aware of different version of VB, so not sure what to reply to that.
Yes, Microsoft Workflow Foundation, that OpenRPA ( and UiPath ) uses to create an GUI that allows working with sequence and flow diagrams, uses VB Expressions in all property fields. This way you can give it static values or function calls that return a value.

anonymous is a perfect name for that. That is what most people called them back when they were introduced in dot net … I think many call it lambda functions now. If you need to google it and find examples, you would search for linq queries, a variation used to do filters and manipulation on lists. Here we grabbing the name of the iElement object and only returning the name property, in effect creating an array of strings.

The structure is a Get Element, within which is a Sequence, within which is the ForEach. The xpath in the Selector of the Get Element finds the div that contains the select tag and then has “/select”. Using Highlight shows the correct (closed) drop down. There is a compiler error for the “” which says “‘item’ is not declared. It may be inaccessible due to its protection level.”. This appears to have been caused by the way the structure was established because I deleted the Sequence (and therefore the ForEach) and then inserted a ForEach which worked. I think you only get a Sequence if you insert more than one item, so having a Sequence containing only one item presumably means I had another item that I deleted.

However, this has just led me to another dead end. I now have a Get Element that, whilst it can highlight the correct page item, does not execute the WriteLine within its scope. There is no error of any sort. If the xpath of the selector fails to locate a node (e.g. there is a “/a” when there are no anchors in the scope) would it not generate an error? I have invalidated the selector by removing the starting // of an “a” and this gives the error “The string ‘//div[@id="ot-desc-id-C0001"]/div[1]a[@class=‘btn btn-success’]’ is not a valid XPath expression”. I had expected what it would prefix the selector with the current value of “item”, which would be the selector I used to give a value to “item”. However, the prefix is not one of my selectors. How can I debug this?

Workflow Foundation will not allow the “host” ( openrpa) to inspect variables in he body of an activity, that is why you always add a sequence and then add activity’s inside it …
If you removed the sequence, you can get a new one by dragging new activity in and find the “spot” where it shows it will add it below or above the existing foreach activity and then drop it. this will create an sequence to hold both activities, and then you can remove the temp one you added.
Then you can select the ForEach activity, and press F9 to set a breakpoint

Sometimes the compiling of workflows is not up to date, so if you don’t see the red mark, close the workflow and open it again. Now when you run the workflow it will stop at the breakpoint and convert the property inspector into a variable inspector, that allows you to see the content of all variables

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.