Partial Attributes Search by Control Type Fails


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");


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.


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

HtmlInputButton button = Find.AllByAttributes<HtmlInputButton>("id=~MyButtonIDPart")[0];
Is this article helpful? Yes / No
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article