Skip to main content

Control and AutomationControl

The WinDriver virtual user has two classes for handling window controls. A control represents a window, dialog, button editbox, etc.

Control

This class is used for objects that are identified by a unique windows handle value. The class calls C++ Windows API calls and sends Windows Messages to query or update the control. This class works well on legacy windows controls written in C, C++ Visual Basic, Delphi and other languages or frameworks, including many .Net applications where the windows controls are based on standard windows controls. Searching and interacting with WinDriver control objects is generally fast and has a low overhead.

It has limitations when the controls are not derived from standard windows classes, for instance certain "custom controls" or for controls using other GUI frameworks such as Windows Presentation Foundation (WPF) controls or controls displayed in web browsers. For these controls you can try the AutomationControl.

AutomationControl

This class wraps the Windows Automation Element object so it is very similar in usage to the WinDriver Control class. It enables scripts to work with controls created using frameworks such as WPF, Silverlight, HTML pages (IE7 and later), Firefox and even some Java UI frameworks. You can use a tool such as Microsoft's UISpy tool to identify the controls and their properties. Windows Automation Element objects have large set of methods and properties for working with the control and these have a consistency that applies to many different control types. Searching for AutomationControl objects can have a high overhead particularly when there are a large number of objects in the Windows control hierarchy (although the default MaxSearchDepth of 3 will limit the elapsed time)

The AutomationControl class was developed to allow working with objects that were not visible using the basic WinDriver Control class. It has almost the same methods for consistency.

The Control class method ToAutomationControl is a convenient method for converting an Control object to an AutomationControl object. This is useful when a parent object can be quickly found using Control methods but the contents may only be found using AutomationControl methods.