Problem with For Each loop with UiElement array

I am grabbing the rows from a table using the find children activity with scope find_descendants.
I am able to grab the UiElements and store them in a collection variable. The filter I am using for the find children activity is: "<ctrl name=“Row *’ role=‘row’ />”

Once I have the collection, I use a for each loop to loop through each item and click the row in the table. In debug mode, the collection shows three items correctly (Row 0, Row 1, Row 2) and clicks each one correctly.

When I execute the project normally, the first row (Row 0) gets selected correctly. Once the loop tries to grab the next UiElement in the collection, UiPath errors and gives me an exception due to not being able to find UiElement “Row -1”.

I am not sure if this is a bug or if there is a reason the loop is trying to grab “Row -1” when running normally but then correctly grabbing “Row 1” and then “Row 2” when working in debug mode.

Any help is appreciated.

Hi @miles.oconnor,
Can u share your workflow.

Hi Miles,

If it is working i. Debug mode and not Woking in normal execution, then there must be some problems related to loading the data . My suggestion will be add some dalay inside for each loop and check. If it works fine, you can replace static delay with dynamic delay ( element exists).



I debugged and this only happened at the end of the loop and would error out once the loop iterated to the next item. I debugged this with another co-worker and was not able to resolve the issue of the selector row going to -1 when reaching the end of the loop and incrementing to the next item.

I ended up finding a reusable selector set the selector to a variable. From there I added a variable (i) and concatenated the number I was iterating through (i) as the row number in the selector variable and then used that variable in the click activity.

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