Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can be instantiated the type AutomationElement given an AutomationId value?

I would like to know, in .NET, if the (managed)Microsoft UI Automation framework provides some way to instantiate an AutomationElement type given the AutomationId value of a window, suppressing this way the need to search the window by a window handle or other kind of identifiers.

A pseudo example written in VB.NET to understand my purpose:

Dim automationId As Integer = 1504
Dim element As AutomationElement = AutomationElement.FromAutomationId(automationId)
like image 900
ElektroStudios Avatar asked Sep 22 '16 19:09

ElektroStudios


People also ask

What is AutomationId?

The AutomationId property used to define the unique string and it helps to identify the specified element in Automation testing process and perform recorded action. For example, you are setting AutomationId for RibbonTab. The following code demonstrates the same. XAML.

What is AutomationElement?

An AutomationElement corresponds to a piece of user interface (UI), regardless of underlying implementation (such as Windows Presentation Foundation (WPF) or Win32).


1 Answers

Well, no. Any automation property is a property of the element. Automation elements don't necessarily correspond to HWNDs (every HWND has an automation element, but very few automation elements have HWNDs, particularly in modern UI frameworks), and therefore a tree walk is required. Also, the nice thing about UI Automation is that the tree walk occurs on the provider side, not in your application, reducing the number of cross-process calls.

like image 124
Eric Brown Avatar answered Sep 28 '22 08:09

Eric Brown