title | description | ms.date | dev_langs | helpviewer_keywords | ms.topic | ||||
---|---|---|---|---|---|---|---|---|---|
Find a UI Automation Element Based on a Property Condition |
Find a UI Automation element based on a property condition. Locate an element within the UI Automation tree based on a specific property or properties. |
03/30/2017 |
|
|
how-to |
Note
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes defined in the xref:System.Windows.Automation namespace. For the latest information about UI Automation, see Windows Automation API: UI Automation.
This article contains example code that shows how to locate an element within the UI Automation tree based on a specific property or properties.
In the following example, a set of property conditions are specified that identify a certain element (or elements) of interest in the xref:System.Windows.Automation.AutomationElement tree. A search for all matching elements is then performed with the xref:System.Windows.Automation.AutomationElement.FindAll%2A method that incorporates a series of xref:System.Windows.Automation.AndCondition Boolean operations to limit the number of matching elements.
Note
When searching from the xref:System.Windows.Automation.AutomationElement.RootElement%2A, you should try to obtain only direct children. A search for descendants might iterate through hundreds or even thousands of elements, possibly resulting in a stack overflow. If you are attempting to obtain a specific element at a lower level, you should start your search from the application window or from a container at a lower level.
[!code-csharpInvokePatternApp#1100] [!code-vbInvokePatternApp#1100]