cancel
Showing results for 
Search instead for 
Did you mean: 

Use .Find to get all elements that do NOT match the search properties

SOLVED
Highlighted
Community Hero

Use .Find to get all elements that do NOT match the search properties

Hi all,

 

I'm trying to find a way to make my code less loopy and possibly improve the performance.  I'm trying to take a list of items, get rid of the items that I'm not interested in, and keep the rest

 

Example items*:

Red Tomato

Orange Carrot

Red Strawberry

Green Lettuce

Red Cherry

...

 

I wan't to find all the fruit/veg that aren't red.  I don't know how many fruit or vegetables there are that aren't red - this can vary - but I expect that the majority of the fruit/veg will be red.  I can't go through all the colours that aren't red and find them one by one and add them, because I don't know which colours of fruit/veg there will be.  I could find ALL the fruit/veg then loop through those objects and remove everything that's red - which is what I generally do now - but it seems a waste to return such a large amount of items if all I need to do is use a NOT filter, which will return two or three of the 50 items.  Is there a way to do that ?

 

*Surnames removed to protect identities

 

 

 


-------------------------------------------------
Standard syntax disclaimers apply
Regards,
2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Community Hero

Re: Use .Find to get all elements that do NOT match the search properties

Hi,

 

The below may appear to be not relevant for your real case because I don't know how color is determined, but as an idea you may consider using regular expressions for search parameters.

Sample pseudocode:

var objects = root.FindAllChildren(['Type', 'Color'], ['regexp: (vegetable)|(fruit)', 'regexp:^(red)'], depth);

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

Highlighted
Community Hero

Re: Use .Find to get all elements that do NOT match the search properties

That is SOO exactly what I was looking for, thanks ! Smiley Very Happy

Syntax correction:

It's 'regexp:[^(red)]' - it was just missing the [] around the ^(red)

 


-------------------------------------------------
Standard syntax disclaimers apply
Regards,

View solution in original post

5 REPLIES 5
Highlighted
Community Hero

Re: Use .Find to get all elements that do NOT match the search properties

Hi,

 

The below may appear to be not relevant for your real case because I don't know how color is determined, but as an idea you may consider using regular expressions for search parameters.

Sample pseudocode:

var objects = root.FindAllChildren(['Type', 'Color'], ['regexp: (vegetable)|(fruit)', 'regexp:^(red)'], depth);

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

Highlighted
Community Hero

Re: Use .Find to get all elements that do NOT match the search properties

That is SOO exactly what I was looking for, thanks ! Smiley Very Happy

Syntax correction:

It's 'regexp:[^(red)]' - it was just missing the [] around the ^(red)

 


-------------------------------------------------
Standard syntax disclaimers apply
Regards,

View solution in original post

Highlighted
Community Hero

Re: Use .Find to get all elements that do NOT match the search properties

Hi,

 

That is SOO exactly

Wow, great to hear! 🙂

 

Syntax correction:

May be, needs to be checked.

To my understanding, [red] will match if the string been processed contains either 'r', or 'e', or 'd'.

While (red) should match 'red' exactly.

But I might be wrong and, as I said, exact syntax needs verification.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
Highlighted
Community Hero

Re: Use .Find to get all elements that do NOT match the search properties

> Syntax correction

Not a critisism, just an update for future readers of the post Smiley Happy

> While (red) should match 'red' exactly

That's the result I got when testing [red] versus (red)


-------------------------------------------------
Standard syntax disclaimers apply
Regards,
Highlighted
Community Hero

Re: Use .Find to get all elements that do NOT match the search properties

I see, thank you a lot for correction then.

 

[Update]

> It's 'regexp:[^(red)]' - it was just missing the [] around the ^(red)

Ah, got it 🙂

The corrected regexp will match a string that does not contain a token and token equals to 'red'. I.e. effectively regexp will match everything that does not contain 'red'.

Thank you again for correction -- I'll definitely bookmark it.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!

Challenge Status

Changing options from outside of TestComplete

Participate!

How to execute remote test and obtain results via Test Runner REST API

Participate!

Comparing content of HTML table with Excel file data

Participate!

Compare HTML table with Excel file and correct data in the file

Participate!
Top Kudoed Authors