Skip to content

Latest commit

 

History

History
41 lines (25 loc) · 1.82 KB

partial-attributes-search-fails.md

File metadata and controls

41 lines (25 loc) · 1.82 KB
title page_title description previous_url position
Partial Attributes Search Fails
Partial Attributes Search Fails
Test Studio is an innovative and easy-to-use automated web, WPF and load testing solution. Test Studio tests support essential technologies like ASP.NET AJAX, Silverlight, PHP and MVC. HTML5, Testing framework, functional testing, performance testing, load testing, exploratory testing, manual testing.
/user-guide/code-samples/html/search-control-type-by-partial-attributes-fails.aspx, /user-guide/code-samples/html/search-control-type-by-partial-attributes-fails
1

#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 overload and return the first (and actually the only completely matching control):

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