Partial Attributes Search by Control Type Fails

PROBLEM

A partial search of control by attribute may return null even with correct partial search syntax. For example a HtmlInputButton search on the page having a complex ID containing some specific string should be located successfully using the following syntax:

 

HtmlInputButton button = Find.ById<HtmlInputButton>("~MyButtonIDPart");
 

Although the next example works:

 

HtmlInputButton button = Find.ById<HtmlInputButton>("SomeButtonIDPart_MyButtonIDPart");

DESCRIPTION

The framework locates the first element matching the given attribute search criteria. Next, it compares the control type of the element and returns that element if the control type matches. If it does not, it simply returns null.

 

In the first example, the framework returns null if there is another element that matches the given attribute search criteria and it is found before the target element. The control type does not match.

SOLUTION

A simple solution is available. Use Find.AllByAttributes<Control Type> overload and return the first (and actually the only completely matching control):

 

HtmlInputButton button = Find.AllByAttributes<HtmlInputButton>("id=~MyButtonIDPart")[0];
 

A sample test project is attached to demonstrate the framework behavior along with the solution.

 

We will surely consider improving the framework behavior in the future so that it can continue searching for the required control, even if the first control type comparison does not match.