This project is read-only.

Custom Conditions

Jan 23, 2009 at 6:23 AM

I wanted to create a custom condition and then use it in the SearchCriteria, but it does not seem possible.

Basically I want to create a ContainsCondition which passes if the text being searched simply contains some subset.  ie. Contains("Hello") passes if the element name is "Hello World"

First I tried creating a class inheriting from SearchCondition, no go because of required ToString override

Then I inherited from NameCondition and overrode Satisfies, which is fine..

But there seems to be no way to put my custom condition into a SearchCriteria.

Is what I am trying possible?  Are there alternatives?

Jan 26, 2009 at 3:09 PM
i am afraid this feature is not there currently as you are asking for. the reason being the white's search mechanism is tied to UIA search mechanism. it is not possible to do the same in UIA hence not in white too.
is there a reason you are not searching by automation id?
there is a way to do this, which is to use window.FindAll(...).Find(...pass you delegate here....). the peformance would not be bad though.
Jan 26, 2009 at 11:26 PM
I am not searching by Automation Id because I just thought it would be easier to get the window by a subset of it's title - the reason I only wanted to match by a subset is because the window title can change depending on certain conditions.

If you look at NameCondition, the Satisfies method, if I have been able to override that I could have used "return element.Current.Name.Contains(name)" to acheive what I wanted.

It appears that Application.Find does not wait whereas Application.GetWindow does.
If I use the Find method, what do I have to do to make it wait in the same way that GetWindow does?

Jan 26, 2009 at 11:28 PM
Note also that Application.Find only handles the finding of windows by Title, whereas leveraging the Condition and SearchCriteria infrastructure would allow searches on other elements.

Mar 10, 2009 at 8:12 PM
Note that UIA allows you to search by any AutomationProperty, but White only allows you to search by about five of the thirty or so properties.

In order to create a custom search, you need to:
1. Change the private constructor for SearchCriteria to public
2. Change the protected internal method SearchCondition.ToString(string) to public
3. Rebuild
Mar 14, 2009 at 11:18 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.