Quickly Remove select uielements from find children output?

Hi all,

I have used a FindChildren activity to find a group of uielements from our in-house software. I then use a for-each loop to iterate through each element and perform activities on those elements IF the uielement has a specific text in the title attribute.

However… I find it can take a while for uipath to iterate through each uielement (even there will be a lot more unneed elements, rather than ones i’m interested in). Is there a quick/instant way to remove all the elements that do not have a specific text in the title attribute rather than using the foreach loop? Not the end of the world if not, but would be nice to speed up the process slightly…

@adam.williamson Firstly We would need to know with which attribute of the UiElement you are trying to compare your value. So for that, you can go on ahead with UiExplorer and Notify us the Attribute which supposedly contains the value. Then we can use a Linq Query to Only keep the UiElements that you require. The Linq Query can be in the below manner. Suppose the Value is present in the “aaname” attribute then you can use this in an assign activity :

children = children.Where(Function(x)x.Get(“aaname”).ToString.Trim.Equals(“yourValue”)).ToArray

Where children is the Ouput of Find Children Activity.

But there may be cases when this won’t give the right output when looping since you would even need to loop the cases which you won’t need.

Try it and let us know

2 Likes

That nearly works.

ui_jobSteps.Where(Function(x)x.Get(“title”).ToString.Trim.Contains(“Appointment Completed”)).ToArray

However, the attribute can either be “Appointment Completed”, or it can be “Arrived On Site”. Is there a way to filter for both options? Note that it is super important that the order of elements remains the same as from the original FindChildren activity - so I can’t just create 2 arrays and join them together… ?

@adam.williamson
you can define for this an array eg: FilterValues = {“Appointment Completed”,“Appointment Completed”}

the modified LINQ should now handle both:

ui_jobSteps.Where(Function(x) FilterValues.Contains(x.Get(“title”).ToString.Trim)).ToArray

kindly note: the contains is not a string contains it the contains method from Array/Collections

1 Like

Thanks, but unfortunately it doesn’t work with the Contains being used on the Array instead of the title/attribute of the uielement. I don’t suppose there’s any other way to get this to work? (sorry, Linq isn’t my strong-suit…)

Thanks :slight_smile:

just help on more clear understanding:

the LINQ should filter uielements from the find children where the title is “Appointment Completed or “Appointment Completed” is this understanding correct?

That’s correct - HOWEVER, the title will also contain other text too which can’t be predicted, which is why I have been using the ‘Contains’ rather than ‘Equals’ because the actual title might be “Appointment Completed on XX/XX/XXXX by ABC” for example

@adam.williamson
perfect,

lets shift from the Method Syntax to the Query Syntax

(From ue In ui_jobSteps
Where FilterValues.Any(Function (x) ue.Get(“title”).ToString.Trim.Contains(x))
Select ue).toArray

2 Likes

That seems to be working. Need to test it a little more to make sure the results remain consistent vs the old method - however, the foreach loop took 3:49 to complete, and the new method only takes 1:18 so a notable improvement. Thanks :smiley:

1 Like

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