UI Automation
UI Automation
UI Automation
Accessibility
Accessibility Best Practices
UI Automation Fundamentals
UI Automation Overview
UI Automation and Microsoft Active Accessibility
UI Automation Tree Overview
UI Automation Control Patterns Overview
UI Automation Properties Overview
UI Automation Events Overview
UI Automation Security Overview
Using UI Automation for Automated Testing
UI Automation Providers for Managed Code
Server-Side UI Automation Provider Implementation
UI Automation Providers Overview
Client-Side UI Automation Provider Implementation
How-to Topics
UI Automation Clients for Managed Code
UI Automation and Screen Scaling
UI Automation Support for Standard Controls
UI Automation Events for Clients
Caching in UI Automation Clients
UI Automation Properties for Clients
Control Pattern Mapping for UI Automation Clients
UI Automation Control Patterns for Clients
Obtaining UI Automation Elements
UI Automation Threading Issues
How-to Topics
UI Automation Control Patterns
Implementing the UI Automation Dock Control Pattern
Implementing the UI Automation ExpandCollapse Control Pattern
Implementing the UI Automation Grid Control Pattern
Implementing the UI Automation GridItem Control Pattern
Implementing the UI Automation Invoke Control Pattern
Implementing the UI Automation MultipleView Control Pattern
Implementing the UI Automation RangeValue Control Pattern
Implementing the UI Automation Scroll Control Pattern
Implementing the UI Automation ScrollItem Control Pattern
Implementing the UI Automation Selection Control Pattern
Implementing the UI Automation SelectionItem Control Pattern
Implementing the UI Automation Table Control Pattern
Implementing the UI Automation TableItem Control Pattern
Implementing the UI Automation Toggle Control Pattern
Implementing the UI Automation Transform Control Pattern
Implementing the UI Automation Value Control Pattern
Implementing the UI Automation Window Control Pattern
How-to Topics
UI Automation Text Pattern
UI Automation TextPattern Overview
TextPattern and Embedded Objects Overview
How-to Topics
UI Automation Control Types
UI Automation Control Types Overview
UI Automation Support for the Button Control Type
UI Automation Support for the Calendar Control Type
UI Automation Support for the CheckBox Control Type
UI Automation Support for the ComboBox Control Type
UI Automation Support for the DataGrid Control Type
UI Automation Support for the DataItem Control Type
UI Automation Support for the Document Control Type
UI Automation Support for the Edit Control Type
UI Automation Support for the Group Control Type
UI Automation Support for the Header Control Type
UI Automation Support for the HeaderItem Control Type
UI Automation Support for the Hyperlink Control Type
UI Automation Support for the Image Control Type
UI Automation Support for the List Control Type
UI Automation Support for the ListItem Control Type
UI Automation Support for the Menu Control Type
UI Automation Support for the MenuBar Control Type
UI Automation Support for the MenuItem Control Type
UI Automation Support for the Pane Control Type
UI Automation Support for the ProgressBar Control Type
UI Automation Support for the RadioButton Control Type
UI Automation Support for the ScrollBar Control Type
UI Automation Support for the Separator Control Type
UI Automation Support for the Slider Control Type
UI Automation Support for the Spinner Control Type
UI Automation Support for the SplitButton Control Type
UI Automation Support for the StatusBar Control Type
UI Automation Support for the Tab Control Type
UI Automation Support for the TabItem Control Type
UI Automation Support for the Table Control Type
UI Automation Support for the Text Control Type
UI Automation Support for the Thumb Control Type
UI Automation Support for the TitleBar Control Type
UI Automation Support for the ToolBar Control Type
UI Automation Support for the ToolTip Control Type
UI Automation Support for the Tree Control Type
UI Automation Support for the TreeItem Control Type
UI Automation Support for the Window Control Type
UI Automation Specification and Community Promise
Accessibility
4/14/2017 1 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
Microsoft UI Automation is the new accessibility framework for Microsoft Windows. It addresses the needs of
assistive technology products and automated test frameworks by providing programmatic access to information
about the user interface (UI). In addition, UI Automation enables control and application developers to make their
products accessible.
This documentation describes the UI Automation API for managed code. For information on programming for UI
Automation in C++, see UI Automation for Win32 Applications.
In This Section
Accessibility Best Practices
UI Automation Fundamentals
UI Automation Providers for Managed Code
UI Automation Clients for Managed Code
UI Automation Control Patterns
UI Automation Text Pattern
UI Automation Control Types
UI Automation Specification and Community Promise
Related Sections
Accessibility Samples
Accessibility Best Practices
4/14/2017 5 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes defined
in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows Automation
API: UI Automation.
Implementing the following best practices in controls or applications will improve their accessibility for people who
use assistive technology devices. Many of these best practices focus on good user interface (UI) design. Each best
practice includes implementation information for Windows Presentation Foundation (WPF) controls or applications.
In many cases, the work to meet these best practices is already included in WPF controls.
Programmatic Access
Programmatic access involves ensuring that all UI elements are labeled, property values are exposed, and
appropriate events are raised. For standard WPF controls, most of this work is already done through
AutomationPeer. Custom controls require additional work to ensure that programmatic access is correctly
implemented.
Enable Programmatic Access to all UI Elements and Text
User interface (UI) elements should enable programmatic access. If the UI is a standard WPF control, support for
programmatic access is included in the control. If the control is a custom control a control that has been
subclassed from a common control or a control that has been subclassed from Control then you must check the
AutomationPeer implementation for areas that may need modification.
Following this best practice allows assistive technology vendors to identify and manipulate elements of your
product's UI.
Place Names, Titles, and Descriptions on UI Objects, Frames, and Pages
Assistive technologies, especially screen readers, use the title to understand the location of the frame, object, or
page in the navigation scheme. Therefore, the title must be very descriptive. For example, a Web page title of
"Microsoft Web Page" is useless if the user has navigated deeply into some particular area. A descriptive title is
critical for users who are blind and depend on screen readers. Similarly, for Windows Presentation Foundation
(WPF) controls, NameProperty and HelpTextProperty are important for assistive technology devices.
Following this best practice allows assistive technologys to identify and manipulate UI in sample controls and
applications.
Ensure Programmatic Events Are Triggered by All UI Activities
Following this best practice allows assistive technologys to listen for changes in the UI and notify the user about
these changes.
User Settings
The best practice in this section ensures that controls or applications do not override user settings.
Respect All System-Wide Settings and Do Not Interfere with Accessibility Functions
Users can use the Control Panel to set some system-wide flags; other flags can be set programmatically. These
settings should not be changed by controls or applications. Also, applications must support the accessibility settings
of their host operating system.
Following this best practice allows users to set accessibility settings and know that those settings will not be
changed by applications.
Visual UI Design
Best Practices in this section ensure that controls or applications use color and images effectively and are able to be
used by Assistive technologies.
Don't Hard-Code Colors
People who are color blind, have low vision, or are using a black and white screen might not be able to use
applications with hard-coded colors.
Following this best practice allows users to adjust color combinations based on individual needs.
Support High Contrast and all System Display Attributes
Applications should not disrupt or disable user-selected, system-wide contrast settings, color selections, or other
system-wide display settings and attributes. System-wide settings adopted by a user enhance the accessibility of
applications, so they should not be disabled or disregarded by applications. Color should be used in their correct
foreground-on-background combination to provide proper contrast. Unrelated colors should not be mixed, and
colors should not be reversed.
Many users require specific high-contrast combinations, such as white text on a black background. Drawing these
reversed, as black text on a white background causes the background to bleed over the foreground and can make
reading difficult for some users.
Ensure All UI Correctly Scales by Any DPI Setting
Ensure that all UI can correctly scale by any dots per inch (dpi) setting. Also, ensure that UI elements fit in a screen
of 1024 x 768 with 120 dots per inch (dpi).
Navigation
Best Practices in this section ensure that navigation has been addressed for controls and applications.
Provide Keyboard Interface for All UI Elements
Tab stops, especially when carefully planned, give users another way to navigate the UI.
Applications should provide the following keyboard interfaces:
tab stops for all controls that the user can interact with, such as buttons, links, or list boxes
logical tab order
Show the Keyboard Focus
Users need to know which object has the keyboard focus so that they can anticipate the effect of their keystrokes.
To highlight the keyboard focus, use colors, fonts, or graphics such as rectangles or magnification. To audibly
highlight the keyboard focus, change the volume, pitch or tonal quality.
To avoid confusion, applications should hide all visual focus indicators and dim selections that are located in
inactive windows (or panes).
Applications should do the following with keyboard focus:
one item should always have keyboard focus
keyboard focus should be visible and obvious
selections and/or focused items should be visually highlighted
Support Navigation Standards and Powerful Navigation Schemes
Different aspects of keyboard navigation provide different ways for users to navigate the UI.
Applications should provide the following keyboard interfaces:
shortcut keys and underlined access keys for all commands, menus and controls
keyboard shortcuts to important links
all menu items have an access key; all buttons have accelerator keys, all commands have an accelerator key.
Do Not Let Mouse Location Interfere with Keyboard Navigation
Mouse location should not interfere with keyboard navigation. For example, if the mouse is positioned someplace
and the user is navigating with the keyboard, a mouse click should not happen unless initiated by the user.
Multimodal Interface
Best Practices in this section ensure that application UI includes alternatives for visual elements.
Provide User-Selectable Equivalents for Non-Text Elements
For each non-text element, provide a user-selectable equivalent for text, transcripts, or audio descriptions, such as
alt text, captions, or visual feedback.
Non-text elements cover a wide range of UI elements including: images, image map regions, animations, applets,
frames, scripts, graphical buttons, sounds, stand-alone audio files and video. Non-text elements are important when
they contain visual information, speech, or general audio information that the user needs access to in order to
understand the content of the UI.
Use Color but Also Provide Alternatives to Color
Use color to enhance, emphasize, or reiterate information shown by other means, but do not communicate
information by using color alone. Users who are color blind or have a monochrome display need alternatives to
color.
Use Standard Input APIs with Device -Independent Calls
Device-independent calls ensure keyboard and mouse feature equality, while providing assistive technology with
needed information about the UI.
See Also
System.Windows.Automation.Peers
NumericUpDown Custom Control with Theme and UI Automation Support Sample
Guidelines for Keyboard User Interface Design
UI Automation Fundamentals
4/14/2017 1 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes defined
in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows Automation
API: UI Automation.
In This Section
UI Automation Overview
UI Automation and Microsoft Active Accessibility
UI Automation Tree Overview
UI Automation Control Patterns Overview
UI Automation Properties Overview
UI Automation Events Overview
UI Automation Security Overview
Using UI Automation for Automated Testing
Reference
System.Windows.Automation
System.Windows.Automation.Provider
System.Windows.Automation.Text
UIAutomationClientsideProviders
UI Automation Overview
4/14/2017 4 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
Microsoft UI Automation is the new accessibility framework for Microsoft Windows, available on all operating
systems that support Windows Presentation Foundation (WPF).
UI Automation provides programmatic access to most user interface (UI) elements on the desktop, enabling
assistive technology products such as screen readers to provide information about the UI to end users and to
manipulate the UI by means other than standard input. UI Automation also allows automated test scripts to
interact with the UI.
NOTE
UI Automation does not enable communication between processes started by different users through the Run as
command.
UI Automation client applications can be written with the assurance that they will work on multiple
frameworks. The UI Automation core masks any differences in the frameworks that underlie various pieces of
UI. For example, the Content property of a WPF button, the Caption property of a Win32 button, and the
ALT property of an HTML image are all mapped to a single property, Name, in the UI Automation view.
UI Automation provides full functionality in Windows Vista, Microsoft Windows XP, and Windows Server
2003.
UI Automation providers offer some support for Microsoft Active Accessibility client applications, through a
built-in bridging service.
COMPONENT DESCRIPTION
Provider API (UIAutomationProvider.dll and A set of interface definitions that are implemented by UI
UIAutomationTypes.dll) Automation providers, objects that provide information
about UI elements and respond to programmatic input.
Client API (UIAutomationClient.dll and A set of types for managed code that enables UI
UIAutomationTypes.dll) Automation client applications to obtain information about
the UI and to send input to controls.
From the software developer's perspective, there are two ways of using UI Automation: to create support for
custom controls (using the provider API), and creating applications that use the UI Automation core to
communicate with UI elements (using the client API). Depending on your focus, you should refer to different
parts of the documentation. You can learn more about the concepts and gain practical how-to knowledge in
the following sections.
UI Automation Providers for Overviews and how-to topics to help Control developers.
Managed Code you use the provider API.
UI Automation Clients for Managed Overviews and how-to topics to help Client application developers.
Code you use the client API.
The following table lists UI Automation namespaces, the DLLs that contain them, and the audience that uses
them.
UI Automation Model
UI Automation exposes every piece of the UI to client applications as an AutomationElement. Elements are
contained in a tree structure, with the desktop as the root element. Clients can filter the raw view of the tree
as a control view or a content view. Applications can also create custom views.
AutomationElement objects expose common properties of the UI elements they represent. One of these
properties is the control type, which defines its basic appearance and functionality as a single recognizable
entity: for example, a button or check box.
In addition, elements expose control patterns that provide properties specific to their control types. Control
patterns also expose methods that enable clients to get further information about the element and to provide
input.
NOTE
There is not a one-to-one correspondence between control types and control patterns. A control pattern may be
supported by multiple control types, and a control may support multiple control patterns, each of which exposes
different aspects of its behavior. For example, a combo box has at least two control patterns: one that represents its
ability to expand and collapse, and another that represents the selection mechanism. For specifics, see UI Automation
Control Types.
UI Automation also provides information to client applications through events. Unlike WinEvents, UI
Automation events are not based on a broadcast mechanism. UI Automation clients register for specific event
notifications and can request that specific UI Automation properties and control pattern information be
passed into their event handlers. In addition, a UI Automation event contains a reference to the element that
raised it. Providers can improve performance by raising events selectively, depending on whether any clients
are listening.
See Also
UI Automation Tree Overview
UI Automation Control Patterns Overview
UI Automation Properties Overview
UI Automation Events Overview
UI Automation Security Overview
UI Automation and Microsoft Active Accessibility
5/31/2017 10 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
Microsoft Active Accessibility was the earlier solution for making applications accessible. Microsoft UI Automation
is the new accessibility model for Microsoft Windows and is intended to address the needs of assistive technology
products and automated testing tools. UI Automation offers many improvements over Active Accessibility.
This topic includes the main features of UI Automation and explains how these features differ from Active
Accessibility.
Programming Languages
Active Accessibility is based on the Component Object Model (COM) with support for dual interfaces, and is
therefore programmable in C/C++, Microsoft Visual Basic 6.0, and scripting languages. UI Automation (including
the client-side provider library for standard controls) is written in managed code, and UI Automation client
applications are most easily programmed using Microsoft Visual C# or Microsoft Visual Basic .NET. UI Automation
providers, which are interface implementations, can be written in managed code or in C/C++.
In UI Automation, a core service lies between the server (called a provider) and the client. The core service makes
calls to the interfaces implemented by providers and provides additional services such as generating unique
runtime identifiers for elements. Client applications use library functions to call the UI Automation service.
UI Automation providers can provide information to Active Accessibility clients, and Active Accessibility servers can
provide information to UI Automation client applications. However, because Active Accessibility does not expose as
much information as UI Automation, the two models are not fully compatible.
UI Elements
Active Accessibility presents UI elements either as an IAccessible interface or as a child identifier. It is difficult to
compare two IAccessible pointers to determine if they refer to the same element.
In UI Automation, every element is represented as an AutomationElement object. Comparison is done by using the
equality operator or the Equals method, both of which compare the unique runtime identifiers of the elements.
ROLE_SYSTEM_PUSHBUTTON Button
ROLE_SYSTEM_CLIENT Calendar
ROLE_SYSTEM_CLIENT Custom
ROLE_SYSTEM_DOCUMENT Document
ROLE_SYSTEM_TEXT Edit
ROLE_SYSTEM_GROUPING Group
ROLE_SYSTEM_LIST Header
ROLE_SYSTEM_LINK Hyperlink
ROLE_SYSTEM_GRAPHIC Image
ROLE_SYSTEM_LIST List
ROLE_SYSTEM_MENUPOPUP Menu
ROLE_SYSTEM_PANE Pane
ROLE_SYSTEM_SEPARATOR Separator
ROLE_SYSTEM_SLIDER Slider
ACTIVE ACCESSIBILITY ROLE UI AUTOMATION CONTROL TYPE
ROLE_SYSTEM_SPINBUTTON Spinner
ROLE_SYSTEM_PAGETABLIST Tab
ROLE_SYSTEM_TABLE Table
ROLE_SYSTEM_STATICTEXT Text
ROLE_SYSTEM_INDICATOR Thumb
ROLE_SYSTEM_TOOLTIP ToolTip
ROLE_SYSTEM_OUTLINE Tree
ROLE_SYSTEM_WINDOW Window
For more information about the different control types, see UI Automation Control Types.
UI Automation defines many more properties, some of which correspond to states in Active Accessibility. Some are
common to all elements, but others are specific to control types and control patterns. Properties are distinguished
by unique identifiers, and most properties can be retrieved by using a single method, GetCurrentPropertyValue or
GetCachedPropertyValue. Many properties are also easily retrievable from the Current and Cached property
accessors.
A UI Automation provider does not have to implement irrelevant properties, but can simply return a null value
for any properties it does not support. Also, the UI Automation core service can obtain some properties from the
default window provider, and these are amalgamated with properties explicitly implemented by the provider.
As well as supporting many more properties, UI Automation supplies better performance by allowing multiple
properties to be retrieved with a single cross-process call.
The following table shows the correspondence between properties in the two models.
ACTIVE ACCESSIBILITY PROPERTY
ACCESSOR UI AUTOMATION PROPERTY ID REMARKS
get_accName NameProperty
get_accHelp HelpTextProperty
accLocation BoundingRectangleProperty
The following table shows which UI Automation properties correspond to Active Accessibility state constants.
STATE_SYSTEM_FOCUSABLE IsKeyboardFocusableProperty N
STATE_SYSTEM_FOCUSED HasKeyboardFocusProperty N
STATE_SYSTEM_LINKED ControlTypeProperty = N
Hyperlink
ACTIVE ACCESSIBILITY STATE UI AUTOMATION PROPERTY TRIGGERS STATE CHANGE?
STATE_SYSTEM_MOVEABLE CanMoveProperty N
STATE_SYSTEM_MUTLISELECTABLE CanSelectMultipleProperty N
STATE_SYSTEM_PROTECTED IsPasswordProperty N
STATE_SYSTEM_READONLY System.Windows.Automation.RangeVal N
uePattern.IsReadOnlyProperty and
System.Windows.Automation.ValuePatt
ern.IsReadOnlyProperty
STATE_SYSTEM_SELECTED IsSelectedProperty N
STATE_SYSTEM_SIZEABLE CanResize N
STATE_SYSTEM_UNAVAILABLE IsEnabledProperty Y
The following states either were not implemented by most Active Accessibility control servers or have no
equivalent in UI Automation.
For a complete list of UI Automation property identifiers, see UI Automation Properties Overview.
Events
The event mechanism in UI Automation, unlike that in Active Accessibility, does not rely on Windows event routing
(which is closely tied in with window handles) and does not require the client application to set up hooks.
Subscriptions to events can be fine-tuned not just to particular events but to particular parts of the tree. Providers
can also fine-tune their raising of events by keeping track of what events are being listened for.
It is also easier for clients to retrieve the elements that raise events, as these are passed directly to the event
callback. Properties of the element are automatically prefetched if a cache request was active when the client
subscribed to the event.
The following table shows the correspondence of Active Accessibility WinEvents and UI Automation events.
EVENT_OBJECT_CONTENTSCROLLED VerticalScrollPercentProperty or
HorizontalScrollPercentProperty property change on the
associated scroll bars
EVENT_OBJECT_CREATE StructureChangedEvent
EVENT_OBJECT_DEFACTIONCHANGE No equivalent
EVENT_OBJECT_DESTROY StructureChangedEvent
EVENT_OBJECT_FOCUS AutomationFocusChangedEvent
EVENT_OBJECT_HIDE StructureChangedEvent
EVENT_OBJECT_PARENTCHANGE StructureChangedEvent
EVENT_OBJECT_SELECTION ElementSelectedEvent
EVENT_OBJECT_SELECTIONADD ElementAddedToSelectionEvent
WINEVENT UI AUTOMATION EVENT IDENTIFIER
EVENT_OBJECT_SELECTIONREMOVE ElementRemovedFromSelectionEvent
EVENT_OBJECT_SELECTIONWITHIN No equivalent
EVENT_OBJECT_SHOW StructureChangedEvent
EVENT_OBJECT_VALUECHANGE System.Windows.Automation.RangeValuePattern.ValuePropert
y and
System.Windows.Automation.ValuePattern.ValueProperty
changed
EVENT_SYSTEM_ALERT No equivalent
EVENT_SYSTEM_CAPTUREEND No equivalent
EVENT_SYSTEM_CAPTURESTART No equivalent
EVENT_SYSTEM_CONTEXTHELPEND No equivalent
EVENT_SYSTEM_CONTEXTHELPSTART No equivalent
EVENT_SYSTEM_DIALOGEND WindowClosedEvent
EVENT_SYSTEM_DIALOGSTART WindowOpenedEvent
EVENT_SYSTEM_DRAGDROPEND No equivalent
EVENT_SYSTEM_DRAGDROPSTART No equivalent
EVENT_SYSTEM_FOREGROUND AutomationFocusChangedEvent
EVENT_SYSTEM_MENUEND MenuClosedEvent
EVENT_SYSTEM_MENUPOPUPEND MenuClosedEvent
EVENT_SYSTEM_MENUPOPUPSTART MenuOpenedEvent
EVENT_SYSTEM_MENUSTART MenuOpenedEvent
EVENT_SYSTEM_SCROLLINGEND VerticalScrollPercentProperty or
HorizontalScrollPercentProperty property change
WINEVENT UI AUTOMATION EVENT IDENTIFIER
EVENT_SYSTEM_SCROLLINGSTART VerticalScrollPercentProperty or
HorizontalScrollPercentProperty property change
EVENT_SYSTEM_SOUND No equivalent
EVENT_SYSTEM_SWITCHSTART No equivalent
No equivalent ToolTipOpenedEvent
Security
Some IAccessible customization scenarios require wrapping a base IAccessible and calling through to it. This
has security implications, since a partially trusted component should not be an intermediary on a code path.
The UI Automation model removes the need for providers to call through to other provider code. The UI
Automation core service does all the necessary aggregation.
See Also
UI Automation Fundamentals
UI Automation Tree Overview
4/14/2017 4 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation
classes defined in the System.Windows.Automation namespace. For the latest information about UI Automation,
see Windows Automation API: UI Automation.
Assistive technology products and test scripts navigate the UI Automation tree to gather information about
the user interface (UI) and its elements.
Within the UI Automation tree there is a root element (RootElement) that represents the current desktop
and whose child elements represent application windows. Each of these child elements can contain
elements representing pieces of UI such as menus, buttons, toolbars, and list boxes. These elements in turn
can contain elements such as list items.
The UI Automation tree is not a fixed structure and is seldom seen in its totality because it might contain
thousands of elements. Parts of it are built as they are needed, and it can undergo changes as elements are
added, moved, or removed.
UI Automation providers support the UI Automation tree by implementing navigation among items within
a fragment, which consists of a root (usually hosted in a window) and a subtree. However, providers are
not concerned with navigation from one control to another. This is managed by the UI Automation core,
using information from the default window providers.
Content View
The content view of the UI Automation tree is a subset of the control view. It contains UI items that convey
the true information in a user interface, including UI items that can receive keyboard focus and some text
that is not a label on a UI item. For example, the values in a drop-down combo box will appear in the
content view because they represent the information being used by an end user. In the content view, a
combo box and list box are both represented as a collection of UI items where one, or perhaps more than
one, item can be selected. The fact that one is always open and one can expand and collapse is irrelevant in
the content view because it is designed to show the data, or content, that is being presented to the user.
The content view is obtained by searching for elements that have the IsContentElement property set to
true , or by using the ContentViewWalker to navigate the tree.
See Also
AutomationElement
UI Automation Overview
UI Automation Control Patterns Overview
4/14/2017 5 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation
classes defined in the System.Windows.Automation namespace. For the latest information about UI Automation,
see Windows Automation API: UI Automation.
This overview introduces Microsoft UI Automation control patterns. Control patterns provide a way to
categorize and expose a control's functionality independent of the control type or the appearance of the
control.
UI Automation uses control patterns to represent common control behaviors. For example, you use the
Invoke control pattern for controls that can be invoked (such as buttons) and the Scroll control pattern for
controls that have scroll bars (such as list boxes, list views, or combo boxes). Because each control pattern
represents a separate functionality, they can be combined to describe the full set of functionality
supported by a particular control.
NOTE
Aggregate controlsbuilt with child controls that provide the user interface (UI) for functionality exposed by the
parentshould implement all control patterns normally associated with each child control. In turn, those same
control patterns are not required to be implemented by the child controls.
See Also
UI Automation Control Patterns for Clients
Control Pattern Mapping for UI Automation Clients
UI Automation Overview
UI Automation Properties for Clients
UI Automation Events for Clients
UI Automation Properties Overview
4/14/2017 3 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
UI Automation providers expose properties on Microsoft UI Automation elements. These properties enable UI
Automation client applications to discover information about pieces of the user interface (UI), especially controls,
including both static and dynamic data.
This section gives a broad overview of Microsoft UI Automation properties. More specific information is given in
the following topics:
UI Automation Properties for Clients
Server-Side UI Automation Provider Implementation
Property Identifiers
Every property is identified by a number and a name. The names of properties are used only for debugging and
diagnosis. Providers use the numeric IDs to identify incoming property requests. Client applications, however, only
use AutomationProperty, which encapsulates the number and name, to identify properties they wish to retrieve.
AutomationProperty objects representing particular properties are available as fields in various classes. For
security reasons, UI Automation providers obtain these objects from a separate set of classes that are contained in
Uiautomationtypes.dll.
The following table categorizes properties by the classes that contain the AutomationPropertyIDs.
KINDS OF PROPERTIES CLIENTS GET IDS FROM PROVIDERS GET IDS FROM
Properties by Category
The following tables categorize the properties whose IDs are found in AutomationElement and
AutomationElementIdentifiers. These properties are common to all controls. All but a few of them are likely to be
static over the lifetime of the provider application; most dynamic properties are associated with control patterns.
The Property Access column lists any other accessors for each property, in addition to GetCurrentPropertyValue
and GetCachedPropertyValue. For more information on getting properties in a client application, see UI
Automation Properties for Clients.
NOTE
For specific information about each property, follow the link in the Property Access column.
Display Characteristics
PROPERTY IDENTIFIER PROPERTY ACCESS
BoundingRectangleProperty BoundingRectangle
CultureProperty n/a
HelpTextProperty HelpText
IsOffscreenProperty IsOffscreen
OrientationProperty Orientation
Element Type
PROPERTY IDENTIFIER PROPERTY ACCESS
ControlTypeProperty ControlType
IsContentElementProperty IsContentElement
IsControlElementProperty IsControlElement
ItemTypeProperty ItemType
LocalizedControlTypeProperty LocalizedControlType
Identification
PROPERTY IDENTIFIER PROPERTY ACCESS
AutomationIdProperty AutomationId
ClassNameProperty ClassName
FrameworkIdProperty FrameworkId
LabeledByProperty LabeledBy
NameProperty Name
ProcessIdProperty ProcessId
RuntimeIdProperty GetRuntimeId
NativeWindowHandleProperty NativeWindowHandle
Interaction
PROPERTY IDENTIFIER PROPERTY ACCESS
AcceleratorKeyProperty AcceleratorKey
AccessKeyProperty AccessKey
ClickablePointProperty GetClickablePoint
HasKeyboardFocusProperty HasKeyboardFocus
IsEnabledProperty IsEnabled
IsKeyboardFocusableProperty IsKeyboardFocusable
IsDockPatternAvailableProperty GetSupportedPatterns
IsExpandCollapsePatternAvailableProperty GetSupportedPatterns
IsGridItemPatternAvailableProperty GetSupportedPatterns
IsGridPatternAvailableProperty GetSupportedPatterns
IsInvokePatternAvailableProperty GetSupportedPatterns
IsMultipleViewPatternAvailableProperty GetSupportedPatterns
IsRangeValuePatternAvailableProperty GetSupportedPatterns
IsScrollItemPatternAvailableProperty GetSupportedPatterns
IsScrollPatternAvailableProperty GetSupportedPatterns
IsSelectionItemPatternAvailableProperty GetSupportedPatterns
IsSelectionPatternAvailableProperty GetSupportedPatterns
IsTableItemPatternAvailableProperty GetSupportedPatterns
IsTablePatternAvailableProperty GetSupportedPatterns
IsTextPatternAvailableProperty GetSupportedPatterns
IsTogglePatternAvailableProperty GetSupportedPatterns
IsTransformPatternAvailableProperty GetSupportedPatterns
IsValuePatternAvailableProperty GetSupportedPatterns
IsWindowPatternAvailableProperty GetSupportedPatterns
Miscellaneous
PROPERTY IDENTIFIER PROPERTY ACCESS
IsRequiredForFormProperty IsRequiredForForm
IsPasswordProperty IsPassword
ItemStatusProperty ItemStatus
Localization
UI Automation providers should present the following properties in the language of the operating system:
AcceleratorKeyProperty
AccessKeyProperty
HelpTextProperty
LocalizedControlTypeProperty
NameProperty
See Also
Caching in UI Automation Clients
UI Automation Properties for Clients
Server-Side UI Automation Provider Implementation
Find a UI Automation Element Based on a Property Condition
Return Properties from a UI Automation Provider
Raise Events from a UI Automation Provider
UI Automation Events Overview
4/14/2017 3 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
Microsoft UI Automation event notification is a key feature for assistive technologies such as screen readers
and screen magnifiers. These UI Automation clients track events that are raised by UI Automation providers
when something happens in the UI and use the information to notify end users.
Efficiency is improved by allowing provider applications to raise events selectively, depending on whether
any clients are subscribed to those events, or not at all, if no clients are listening for any events.
Types of Events
UI Automation events fall into the following categories.
EVENT DESCRIPTION
Element action Raised when a change in the UI results from end user or
programmatic activity; for example, when a button is
clicked or invoked through InvokePattern.
Global desktop change Raised when actions of global interest to the client occur,
such as when the focus shifts from one element to
another, or when a window closes.
Some events do not necessarily mean that the state of the UI has changed. For example, if the user tabs to a
text entry field and then clicks a button to update the field, a TextChangedEvent is raised even if the user did
not actually change the text. When processing an event, it may be necessary for a client application to check
whether anything has actually changed before taking action.
The following events may be raised even when the state of the UI has not changed.
AutomationPropertyChangedEvent (depending on the property that has changed)
ElementSelectedEvent
InvalidatedEvent
TextChangedEvent
System.Windows.Automation.Selectio System.Windows.Automation.Selectio
nItemPattern.ElementRemovedFromS nItemPatternIdentifiers.ElementRemo
electionEvent vedFromSelectionEvent
System.Windows.Automation.Selectio System.Windows.Automation.Selectio
nItemPattern.ElementSelectedEvent nItemPatternIdentifiers.ElementSelect
edEvent
System.Windows.Automation.Selectio
nPattern.InvalidatedEvent System.Windows.Automation.Selectio
nPatternIdentifiers.InvalidatedEvent
System.Windows.Automation.InvokeP
attern.InvokedEvent System.Windows.Automation.InvokeP
atternIdentifiers.InvokedEvent
System.Windows.Automation.Automa
tionElement.LayoutInvalidatedEvent System.Windows.Automation.Automa
tionElementIdentifiers.LayoutInvalidat
System.Windows.Automation.Automa edEvent
tionElement.MenuClosedEvent
System.Windows.Automation.Automa
System.Windows.Automation.Automa tionElementIdentifiers.MenuClosedEv
tionElement.MenuOpenedEvent ent
System.Windows.Automation.TextPatt System.Windows.Automation.Automa
ern.TextChangedEvent tionElementIdentifiers.MenuOpenedE
vent
System.Windows.Automation.TextPatt
ern.TextSelectionChangedEvent System.Windows.Automation.TextPatt
ernIdentifiers.TextChangedEvent
System.Windows.Automation.Automa
tionElement.ToolTipClosedEvent System.Windows.Automation.TextPatt
ernIdentifiers.TextSelectionChangedEv
System.Windows.Automation.Automa ent
tionElement.ToolTipOpenedEvent
System.Windows.Automation.Automa
System.Windows.Automation.Window tionElementIdentifiers.ToolTipClosedE
Pattern.WindowOpenedEvent vent
System.Windows.Automation.Automa
tionElementIdentifiers.ToolTipOpened
Event
System.Windows.Automation.Window
PatternIdentifiers.WindowOpenedEve
nt
CLASS DESCRIPTION
All the event argument classes contain an EventId member. This identifier is encapsulated in an
AutomationEvent.
The AutomationEvent objects used to identify events are obtained by providers from fields in
AutomationElementIdentifiers and control pattern identifier classes such as DockPatternIdentifiers. The
equivalent fields are obtained by client applications from fields in AutomationElement and control pattern
classes such as DockPattern.
For a list of event identifiers, see UI Automation Events for Clients.
See Also
UI Automation Events for Clients
Server-Side UI Automation Provider Implementation
Subscribe to UI Automation Events
UI Automation Security Overview
4/14/2017 2 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This overview describes the security model for Microsoft UI Automation in Windows Vista.
Manifest Files
To gain access to the protected system UI, applications must be built with a manifest file that includes a special
attribute in the manifest file. This uiAccess attribute is included in the requestedExecutionLevel tag, as follows:
<trustInfo xmlns="urn:0073chemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="highestAvailable"
UIAccess="true" />
</requestedPrivileges>
</security>
</trustInfo>
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This overview describes how Microsoft UI Automation can be useful as a framework for programmatic access in
automated testing scenarios.
UI Automation provides a unified object model that enables all user interface (UI) frameworks to expose complex
and rich functionality in an accessible and easily automated manner.
UI Automation was developed as a successor to Microsoft Active Accessibility. Active Accessibility is an existing
framework designed to provide a solution for making controls and applications accessible. Active Accessibility was
not designed with test automation in mind even though it evolved into that role due to the very similar
requirements of accessibility and automation. UI Automation, in addition to providing more refined solutions for
accessibility, is also specifically designed to provide robust functionality for automated testing. For example, Active
Accessibility relies on a single interface to both expose information about the UI and collect the information needed
by AT products; UI Automation separates the two models.
Both a provider and client are required to implement UI Automation for it to be useful as an automated test tool. UI
Automation providers are applications such as Microsoft Word, Excel, and other third-party applications or controls
based on the Microsoft Windows operating system. UI Automation clients include automated test scripts and
assistive technology applications.
NOTE
The intent of this overview is to showcase the new and improved automated testing capabilities of UI Automation. This
overview is not intended to provide information on accessibility features and will not address accessibility other than where
necessary.
UI Automation in a Provider
For a UI to be automated, a developer of an application or control must look at what actions an end-user can
perform on the UI object using standard keyboard and mouse interaction.
Once these key actions have been identified, the corresponding UI Automation control patterns (that is, the control
patterns that mirror the functionality and behavior of the UI element) should be implemented on the control. For
example, user interaction with a combo box control (such as the run dialog) typically involves expanding and
collapsing the combo box to hide or display a list of items, selecting an item from that list, or adding a new value
via keyboard input.
NOTE
With other accessibility models, developers must gather information directly from individual buttons, menus, or other
controls. Unfortunately, every control type comes in dozens of minor variations. In other words, even though ten variations
of a pushbutton may all work the same way and perform the same function, they must all be treated as unique controls.
There is no way to know that these controls are functionally equivalent. Control patterns were developed to represent these
common control behaviors. For more information, see UI Automation Control Patterns Overview.
Implementing UI Automation
As mentioned earlier, without the unified model provided by UI Automation, test tools and developers are required
to know framework-specific information in order to expose properties and behaviors of controls in that framework.
Since there can be several different UI frameworks present at any single time within Windows operating systems,
including Win32, Windows Forms, and Windows Presentation Foundation (WPF), it can be a daunting task to test
multiple applications with controls that seem similar. For example, the following table outlines the framework-
specific property names required to retrieve the name (or text) associated with a button control and shows the
single equivalent UI Automation property.
UI Automation providers are responsible for mapping the framework-specific properties of their controls to the
equivalent UI Automation properties.
Information on implementing UI Automation in a provider can be found at UI Automation Providers for Managed
Code. Information on implementing control patterns is available at UI Automation Control Patterns and UI
Automation Text Pattern.
UI Automation in a Client
The goal of many automated test tools and scenarios is the consistent and repeatable manipulation of the user
interface. This can involve unit testing specific controls through to the recording and playback of test scripts that
iterate through a series of generic actions on a group of controls.
A complication that arises from automated applications is the difficulty synchronizing a test with a dynamic target.
For example, a list box control, such as one contained in the Windows Task Manager, that displays a list of currently
running applications. Since the items in the list box are dynamically updated outside the control of the test
application, attempting to repeat the selection of a specific item in the list box with any consistency is impossible.
Similar issues can also arise when attempting to repeat simple focus changes in a UI that is outside the control of
the test application.
Programmatic Access
Programmatic access provides the ability to imitate, through code, any interaction and experience exposed by
traditional mouse and keyboard input. UI Automation enables programmatic access through five components:
The UI Automation tree facilitates navigation through the structure of the UI. The tree is built from the
collection of hWnd's. For more information, see UI Automation Tree Overview
Automation elements are individual components in the UI. These can often be more granular than an hWnd.
For more information, see UI Automation Control Types Overview.
Automation properties provide specific information about UI elements. For more information, see UI
Automation Properties Overview.
Control patterns define a particular aspect of a control's functionality; they can consist of property, method,
event, and structure information. For more information, see UI Automation Control Patterns Overview.
Automation events provide event notifications and information. For more information, see UI Automation
Events Overview.
Key Properties for Test Automation
The ability to uniquely identify and subsequently locate any control within the UI provides the basis for automated
test applications to operate on that UI. There are several Microsoft UI Automation properties used by clients and
providers that assist in this.
AutomationID
Uniquely identifies an automation element from its siblings. AutomationIdProperty is not localized, unlike a
property such as NameProperty that is typically localized if a product gets shipped in multiple languages. See Use
the AutomationID Property.
NOTE
AutomationIdProperty does not guarantee a unique identity throughout the automation tree. For example, an application
may contain a menu control with multiple top-level menu items that, in turn, have multiple child menu items. These
secondary menu items may be identified by a generic scheme such as "Item1, Item 2, Item3, etc.", allowing duplicate
identifiers for children across top-level menu items.
ControlType
Identifies the type of control represented by an automation element. Significant information can be inferred from
knowledge of the control type. See UI Automation Control Types Overview.
NameProperty
This is a text string that identifies or explains a control. NameProperty should be used with caution since it can be
localized. See UI Automation Properties Overview.
Implementing UI Automation in a Test Application
Add the UI Automation References. The UI Automation dll's necessary for UI Automation clients
are listed here.
Add the System.Windows.Automation namespace. This namespace contains everything UI Automation clients
need to use the capabilities of UI Automation except text
handling.
Add the System.Windows.Automation.Text namespace. This namespace contains everything a UI Automation clients
need to use the capabilities of UI Automation text handling.
Find controls of interest Automated test scripts locate UI Automation elements that
represent controls of interest within the automation tree.
Obtain Control Patterns Control patterns expose common behaviors for functionally
similar controls.
Automate the UI Automated test scripts can now control any UI of interest
from a UI framework using the information and functionality
exposed by the UI Automation control patterns.
Security
For security information, see UI Automation Security Overview.
See Also
UI Automation Fundamentals
UI Automation Providers for Managed Code
4/14/2017 1 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This section contains overviews and how-to topics that describe how to write Microsoft UI Automation providers
for custom user interface (UI) elements.
In This Section
Server-Side UI Automation Provider Implementation
UI Automation Providers Overview
Client-Side UI Automation Provider Implementation
How-to Topics
Server-Side UI Automation Provider Implementation
5/31/2017 8 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This section describes how to implement a server-side UI Automation provider for a custom control.
The implementation for Windows Presentation Foundation (WPF) elements and non-WPF elements (such as
those designed for Windows Forms) is fundamentally different. WPF elements provide support for UI Automation
through a class derived from AutomationPeer. Non-WPF elements provide support through implementations of
provider interfaces.
Security Considerations
Providers should be written so that they can work in a partial-trust environment. Because UIAutomationClient.dll
is not configured to run under partial trust, your provider code should not reference that assembly. If it does so,
the code may run in a full-trust environment but then fail in a partial-trust environment.
In particular, do not use fields from classes in UIAutomationClient.dll such as those in AutomationElement.
Instead, use the equivalent fields from classes in UIAutomationTypes.dll, such as AutomationElementIdentifiers.
INTERFACE DESCRIPTION
INTERFACE DESCRIPTION
The following interfaces provide added functionality but are not required to be implemented.
INTERFACE DESCRIPTION
All other interfaces in the System.Windows.Automation.Provider namespace are for control pattern support.
Requirements for Non-WPF Providers
In order to communicate with UI Automation, your control must implement the following main areas of
functionality:
FUNCTIONALITY IMPLEMENTATION
Enable the client to interact with the control Implement interfaces that support control patterns, such as
IInvokeProvider. Return these pattern providers in your
implementation of GetPatternProvider.
Enable navigation and focusing within a fragment Implement IRawElementProviderFragment for each element
within the fragment. (Not necessary for elements that are not
part of a fragment.)
Enable focusing and location of child element in a fragment Implement IRawElementProviderFragmentRoot. (Not
necessary for elements that are not fragment roots.)
NOTE
The RuntimeIdProperty of a simple element or fragment root hosted in a window is obtained from the window; however,
fragment elements below the root (such as list items in a list box) must provide their own identifiers. For more information,
see GetRuntimeId.
The IsKeyboardFocusableProperty should be returned for providers hosted in a Windows Forms control. In this case, the
default window provider may be unable to retrieve the correct value.
The NameProperty is usually supplied by the host provider. For example, if a custom control is derived from Control, the
name is derived from the Text property of the control.
METHOD DESCRIPTION
The purpose of an event is to notify the client of something taking place in the user interface (UI), whether or not
the activity is triggered by the UI Automation system itself. For example, the event identified by InvokedEvent
should be raised whenever the control is invoked, either through direct user input or by the client application
calling Invoke.
To optimize performance, a provider can selectively raise events, or raise no events at all if no client application is
registered to receive them. The following methods are used for optimization.
METHOD DESCRIPTION
NOTE
Elements of a fragment other than the root must return a null reference from HostRawElementProvider, because they
are not directly hosted in a window, and no default provider can support navigation to and from them.
The structure of the fragment is determined by your implementation of Navigate. For each possible direction
from each fragment, this method returns the provider object for the element in that direction. If there is no
element in that direction, the method returns a null reference.
The fragment root supports navigation only to child elements. For example, a list box returns the first item in the
list when the direction is FirstChild, and the last item when the direction is LastChild. The fragment root does not
support navigation to a parent or siblings; this is handled by the host window provider.
Elements of a fragment that are not the root must support navigation to the parent, and to any siblings and
children they have.
Non-WPF Provider Reparenting
Pop-up windows are actually top-level windows, and so by default appear in the UI Automation tree as children
of the desktop. In many cases, however, pop-up windows are logically children of some other control. For
example, the drop-down list of a combo box is logically a child of the combo box. Similarly, a menu pop-up
window is logically a child of the menu. UI Automation provides support to reparent pop-up windows so that
they appear to be children of the associated control.
To reparent a pop-up window:
1. Create a provider for the pop-up window. This requires that the class of the pop-up window is known in
advance.
2. Implement all properties and patterns as usual for that pop-up, as though it were a control in its own right.
3. Implement the HostRawElementProvider property so that it returns the value obtained from
HostProviderFromHandle, where the parameter is the window handle of the pop-up window.
4. Implement Navigate for the pop-up window and its parent so that navigation is handled properly from the
logical parent to the logical children, and between sibling children.
When UI Automation encounters the pop-up window, it recognizes that navigation is being overridden from the
default, and skips over the pop-up window when it is encountered as a child of the desktop. Instead, the node will
only be reachable through the fragment.
Reparenting is not suitable for cases where a control can host a window of any class. For example, a rebar can
host any type of HWND in its bands. To handle these cases, UI Automation supports an alternative form of HWND
relocation, as described in the next section.
Non-WPF Provider Repositioning
UI Automation fragments may contain two or more elements that are each contained in a window (HWND).
Because each HWND has its own default provider that considers the HWND to be a child of a containing HWND,
the UI Automation tree will, by default, show the HWNDs in the fragment as children of the parent window. In
most cases this is desirable behavior, but sometimes it can lead to confusion because it does not match the
logical structure of the UI.
A good example of this is a rebar control. A rebar contains bands, each of which can in turn contain an HWND-
based control such as a toolbar, an edit box, or a combo box. The default window provider for the rebar HWND
sees the band control HWNDs as children, and the rebar provider sees the bands as children. Because the HWND
provider and the rebar provider are working in tandem and combining their children, both the bands and the
HWND-based controls appear as children of the rebar. Logically, however, only the bands should appear as
children of the rebar, and each band provider should be coupled with the default HWND provider for the control
it contains.
To accomplish this, the fragment root provider for the rebar exposes a set of children representing the bands.
Each band has a single provider that may expose properties and patterns. In its implementation of
HostRawElementProvider, the band provider returns the default window provider for the control HWND, which it
obtains by calling HostProviderFromHandle, passing in the control's window handle. Finally, the fragment root
provider for the rebar implements the IRawElementProviderHwndOverride interface, and in its implementation of
GetOverrideProviderForHwnd it returns the appropriate band provider for the control contained in the specified
HWND.
See Also
UI Automation Providers Overview
Expose a Server-side UI Automation Provider
Return Properties from a UI Automation Provider
Raise Events from a UI Automation Provider
Enable Navigation in a UI Automation Fragment Provider
Support Control Patterns in a UI Automation Provider
Simple Provider Sample
Fragment Provider Sample
UI Automation Providers Overview
4/14/2017 4 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
UI Automation providers enable controls to communicate with UI Automation client applications. In general, each
control or other distinct element in a user interface (UI) is represented by a provider. The provider exposes
information about the element and optionally implements control patterns that enable the client application to
interact with the control.
Client applications do not usually have to work directly with providers. Most of the standard controls in
applications that use the Win32, Windows Forms, or Windows Presentation Foundation (WPF) frameworks are
automatically exposed to the UI Automation system. Applications that implement custom controls may also
implement UI Automation providers for those controls, and client applications do not have to take any special
steps to gain access to them.
This topic provides an overview of how control developers implement UI Automation providers, particularly for
controls in Windows Forms and Win32 windows.
Types of Providers
UI Automation providers fall into two categories: client-side providers and server-side providers.
Client-side providers
Client-side providers are implemented by UI Automation clients to communicate with an application that does not
support, or does not fully support, UI Automation. Client-side providers usually communicate with the server
across the process boundary by sending and receiving Windows messages.
Because UI Automation providers for controls in Win32, Windows Forms, or WPF applications are supplied as part
of the operating system, client applications seldom have to implement their own providers, and this overview
does not cover them further.
Server-side providers
Server-side providers are implemented by custom controls or by applications that are based on a UI framework
other than Win32, Windows Forms, or WPF.
Server-side providers communicate with client applications across the process boundary by exposing interfaces to
the UI Automation core system, which in turn serves requests from clients.
For more information on client views of the UI Automation tree, see UI Automation Tree Overview.
It is the responsibility of the provider implementation to define an element as a content element or a control
element. Control elements may or may not also be content elements, but all content elements are control
elements.
Frameworks
A framework is a component that manages child controls, hit-testing, and rendering in an area of the screen. For
example, a Win32 window, often referred to as an HWND, can serve as a framework that contains multiple UI
Automation elements such as a menu bar, a status bar, and buttons.
Win32 container controls such as list boxes and tree views are considered to be frameworks, because they contain
their own code for rendering child items and performing hit-testing on them. By contrast, a WPF list box is not a
framework, because the rendering and hit-testing is being handled by the containing WPF window.
The UI in an application can be made up of different frameworks. For example, an HWND application window
might contain Dynamic HTML (DHTML) which in turn contains a component such as a combo box in an HWND.
Fragments
A fragment is a complete subtree of elements from a particular framework. The element at the root node of the
subtree is called a fragment root. A fragment root does not have a parent, but is hosted within some other
framework, usually a Win32 window (HWND).
Hosts
The root node of every fragment must be hosted in an element, usually a Win32 window (HWND). The exception
is the desktop, which is not hosted in any other element. The host of a custom control is the HWND of the control
itself, not the application window or any other window that might contain groups of top-level controls.
The host of a fragment plays an important role in providing UI Automation services. It enables navigation to the
fragment root, and supplies some default properties so that the custom provider does not have to implement
them.
See Also
Server-Side UI Automation Provider Implementation
Client-Side UI Automation Provider Implementation
4/14/2017 2 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
Several different user interface (UI) frameworks are in use within Microsoft operating systems, including Win32,
Windows Forms, and Windows Presentation Foundation (WPF). Microsoft UI Automation exposes information
about UI elements to clients. However, UI Automation does not itself have awareness of the different types of
controls that exist in these frameworks and the techniques that are needed to extract information from them.
Instead, it leaves this task to objects called providers. A provider extracts information from a specific control and
hands that information to UI Automation, which then presents it to the client in a consistent manner.
Providers can exist either on the server side or on the client side. A server-side provider is implemented by the
control itself. WPF elements implement providers, as can any third-party controls written with UI Automation in
mind.
However, older controls such as those in Win32 and Windows Forms do not directly support UI Automation. These
controls are served instead by providers that exist in the client process and obtain information about controls using
cross-process communication; for example, by monitoring windows messages to and from the controls. Such
client-side providers are sometimes called proxies.
Windows Vista supplies providers for standard Win32 and Windows Forms controls. In addition, a fallback
provider gives partial UI Automation support to any control that is not served by another server-side provider or
proxy but has a Microsoft Active Accessibility implementation. All these providers are automatically loaded and
available to client applications.
For more information on support for Win32 and Windows Forms controls, see UI Automation Support for
Standard Controls.
Applications can also register other client-side providers.
See Also
Create a Client-Side UI Automation Provider
Implement UI Automation Providers in a Client Application
UI Automation Providers for Managed Code How-to
Topics
4/14/2017 1 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This section contains code examples that demonstrate tasks in writing Microsoft UI Automation providers for user
interface (UI) elements.
In This Section
Expose a Server-side UI Automation Provider
Return Properties from a UI Automation Provider
Raise Events from a UI Automation Provider
Enable Navigation in a UI Automation Fragment Provider
Support Control Patterns in a UI Automation Provider
Create a Client-Side UI Automation Provider
Implement UI Automation Providers in a Client Application
Expose a Server-side UI Automation Provider
4/14/2017 1 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic contains example code that shows how to expose a server-side UI Automation provider that is hosted in
a System.Windows.Forms.Control window.
The example overrides the window procedure to trap WM_GETOBJECT, which is the message sent by the UI
Automation core service when a client application requests information about the window.
Example
/// <summary>
/// Handles WM_GETOBJECT message; others are passed to base handler.
/// </summary>
/// <param name="m">Windows message.</param>
/// <remarks>
/// This method enables UI Automation to find the control.
/// In this example, the implementation of IRawElementProvider is in the same class
/// as this method.
/// </remarks>
protected override void WndProc(ref Message m)
{
const int WM_GETOBJECT = 0x003D;
See Also
UI Automation Providers Overview
Server-Side UI Automation Provider Implementation
Return Properties from a UI Automation Provider
4/14/2017 1 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic contains sample code that shows how a UI Automation provider can return properties of an element to
client applications.
For any property it does not explicitly support, the provider must return null ( Nothing in Visual Basic). This
ensures that UI Automation attempts to obtain the property from another source, such as the host window
provider.
Example
/// <summary>
/// Gets provider property values.
/// </summary>
/// <param name="propId">Property identifier.</param>
/// <returns>The value of the property.</returns>
object IRawElementProviderSimple.GetPropertyValue(int propId)
{
if (propId == AutomationElementIdentifiers.NameProperty.Id)
{
return "Custom list control";
}
else if (propId == AutomationElementIdentifiers.ControlTypeProperty.Id)
{
return ControlType.List.Id;
}
else if (propId == AutomationElementIdentifiers.IsContentElementProperty.Id)
{
return true;
}
else if (propId == AutomationElementIdentifiers.IsControlElementProperty.Id)
{
return true;
}
else
{
return null;
}
}
''' <summary>
''' Gets provider property values.
''' </summary>
''' <param name="propId">Property identifier.</param>
''' <returns>The value of the property.</returns>
Function GetPropertyValue(ByVal propId As Integer) As Object _
Implements IRawElementProviderSimple.GetPropertyValue
See Also
UI Automation Providers Overview
Server-Side UI Automation Provider Implementation
Raise Events from a UI Automation Provider
4/14/2017 1 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic contains example code that shows how to raise an event from a UI Automation provider.
Example
In the following example, a UI Automation event is raised in the implementation of a custom button control. The
implementation enables a UI Automation client application to simulate a button click.
To avoid unnecessary processing, the example checks ClientsAreListening to see whether events should be raised.
/// <summary>
/// Responds to a button click, regardless of whether it was caused by a mouse or
/// keyboard click or by InvokePattern.Invoke.
/// </summary>
private void OnCustomButtonClicked()
{
// TODO Perform program actions invoked by the control.
// Raise an event.
if (AutomationInteropProvider.ClientsAreListening)
{
AutomationEventArgs args = new AutomationEventArgs(InvokePatternIdentifiers.InvokedEvent);
AutomationInteropProvider.RaiseAutomationEvent(InvokePatternIdentifiers.InvokedEvent, this, args);
}
}
See Also
UI Automation Providers Overview
Enable Navigation in a UI Automation Fragment
Provider
5/31/2017 1 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic contains example code that shows how to enable navigation in a UI Automation provider for an element
that is within a fragment.
Example
The following example code implements Navigate for a list item within a list. The parent element is the list box
element, and the sibling elements are other items in the list collection. The method returns null ( Nothing in
Visual Basic) for directions that are not valid; in this case, FirstChild and LastChild, because the element has no
children.
/// <summary>
/// Navigate to adjacent elements in the automation tree.
/// </summary>
/// <param name="direction">Direction to navigate.</param>
/// <returns>The element in that direction, or null.</returns>
/// <remarks>
/// parentControl is the provider for the list box.
/// parentItems is the collection of list item providers.
/// </remarks>
public IRawElementProviderFragment Navigate(NavigateDirection direction)
{
int myIndex = parentItems.IndexOf(this);
if (direction == NavigateDirection.Parent)
{
return (IRawElementProviderFragment)parentControl;
}
else if (direction == NavigateDirection.NextSibling)
{
if (myIndex < parentItems.Count - 1)
{
return (IRawElementProviderFragment)parentItems[myIndex + 1];
}
else
{
return null;
}
}
else if (direction == NavigateDirection.PreviousSibling)
{
if (myIndex > 0)
{
return (IRawElementProviderFragment)parentItems[myIndex - 1];
}
else return null;
}
else return null;
}
''' <summary>
''' Navigate to adjacent elements in the automation tree.
''' </summary>
''' <param name="direction">Direction to navigate.</param>
''' <returns>The element in that direction, or null.</returns>
''' <remarks>
''' parentControl is the provider for the list box.
''' parentItems is the collection of list item providers.
''' </remarks>
Public Function Navigate(ByVal direction As NavigateDirection) As IRawElementProviderFragment _
Implements IRawElementProviderFragment.Navigate
See Also
UI Automation Providers Overview
Server-Side UI Automation Provider Implementation
Support Control Patterns in a UI Automation
Provider
4/14/2017 3 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic shows how to implement one or more control patterns on a UI Automation provider so that client
applications can manipulate controls and get data from them.
Support Control Patterns
1. Implement the appropriate interfaces for the control patterns that the element should support, such as
IInvokeProvider for InvokePattern.
2. Return the object containing your implementation of each control interface in your implementation of
System.Windows.Automation.Provider.IRawElementProviderSimple.GetPatternProvider
Example
The following example shows an implementation of ISelectionProvider for a single-selection custom list box. It
returns three properties and gets the currently selected item.
#region ISelectionProvider Members
/// <summary>
/// Specifies whether selection of more than one item at a time is supported.
/// </summary>
public bool CanSelectMultiple
{
get
{
return false;
}
}
/// <summary>
/// Specifies whether the list has to have an item selected at all times.
/// </summary>
public bool IsSelectionRequired
{
get
{
return true;
}
}
/// <summary>
/// Returns the automation provider for the selected list item.
/// </summary>
/// <returns>The selected item.</returns>
/// <remarks>
/// MyList is an ArrayList collection of providers for items in the list box.
/// SelectedIndex is the index of the selected item.
/// </remarks>
public IRawElementProviderSimple[] GetSelection()
{
if (SelectedIndex >= 0)
{
IRawElementProviderSimple itemProvider = (IRawElementProviderSimple)MyList[SelectedIndex];
IRawElementProviderSimple[] providers = { itemProvider };
return providers;
}
else return null;
}
#endregion ISelectionProvider Members
#Region "ISelectionProvider Members"
''' <summary>
''' Specifies whether selection of more than one item at a time is supported.
''' </summary>
''' <summary>
''' Returns the automation provider for the selected list item.
''' </summary>
''' <returns>The selected item.</returns>
''' <remarks>
''' MyList is an ArrayList collection of providers for items in the list box.
''' SelectedIndex is the index of the selected item.
''' </remarks>
Public Function GetSelection() As IRawElementProviderSimple() _
Implements ISelectionProvider.GetSelection
If SelectedIndex >= 0 Then
Dim itemProvider As IRawElementProviderSimple = DirectCast(MyList(SelectedIndex),
IRawElementProviderSimple)
Dim providers(1) As IRawElementProviderSimple
providers(0) = itemProvider
Return providers
Else
Return Nothing
End If
Example
The following example shows an implementation of GetPatternProvider that returns the class implementing
ISelectionProvider. Most list box controls would support other patterns as well, but in this example a null
reference ( Nothing in Microsoft Visual Basic .NET) is returned for all other pattern identifiers.
/// <summary>
/// Returns the object that supports the specified pattern.
/// </summary>
/// <param name="patternId">ID of the pattern.</param>
/// <returns>Object that implements IInvokeProvider.</returns>
/// <remarks>
/// In this case, the ISelectionProvider interface is implemented in another provider-defined class,
/// ListPattern. However, it could be implemented in the base provider class, in which case the
/// method would simply return "this".
/// </remarks>
object IRawElementProviderSimple.GetPatternProvider(int patternId)
{
if (patternId == SelectionPatternIdentifiers.Pattern.Id)
{
return new ListPattern(myItems, SelectedIndex);
}
else
{
return null;
}
}
''' <summary>
''' Returns the object that supports the specified pattern.
''' </summary>
''' <param name="patternId">ID of the pattern.</param>
''' <returns>Object that implements IInvokeProvider.</returns>
''' <remarks>
''' In this case, the ISelectionProvider interface is implemented in another provider-defined class,
''' ListPattern. However, it could be implemented in the base provider class, in which case the
''' method would simply return "this".
''' </remarks>
Function GetPatternProvider(ByVal patternId As Integer) As Object _
Implements IRawElementProviderSimple.GetPatternProvider
See Also
UI Automation Providers Overview
Server-Side UI Automation Provider Implementation
Create a Client-Side UI Automation Provider
4/14/2017 3 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic contains example code that shows how to implement a client-side UI Automation provider.
Example
The following example code can be built into a dynamic-link library (DLL) that implements a very simple client-side
provider for a console window. The code does not have any useful functionality, but is intended to demonstrate the
basic steps in setting up a provider assembly that can be registered by a UI Automation client application.
using System;
using System.Windows.Automation;
using System.Windows.Automation.Provider;
namespace ClientSideProviderAssembly
{
// The assembly must implement a UIAutomationClientSideProviders class,
// and the namespace must be the same as the name of the DLL, so that
// UI Automation can find the table of descriptors. In this example,
// the DLL would be "ClientSideProviderAssembly.dll"
#region IRawElementProviderSimple
ProviderOptions IRawElementProviderSimple.ProviderOptions
{
get
{
return ProviderOptions.ClientSideProvider;
}
}
IRawElementProviderSimple IRawElementProviderSimple.HostRawElementProvider
{
get
{
return AutomationInteropProvider.HostProviderFromHandle(providerHwnd);
}
}
Imports System
Imports System.Windows.Automation
Imports System.Windows.Automation.Provider
Namespace ClientSideProviderAssembly
' The assembly must implement a UIAutomationClientSideProviders class,
' and the namespace must be the same as the name of the DLL, so that
' UI Automation can find the table of descriptors. In this example,
' the DLL would be "ClientSideProviderAssembly.dll"
Friend Shared Function Create(ByVal hwnd As IntPtr, ByVal idChild As Integer, ByVal idObject As Integer) As
IRawElementProviderSimple
' This provider doesn't expose children, so never expects
' nonzero values for idChild.
If idChild <> 0 Then
Return Nothing
Else
Return New ConsoleProvider(hwnd)
End If
End Function
Private Shared Function Create(ByVal hwnd As IntPtr, ByVal idChild As Integer) As IRawElementProviderSimple
' Something is wrong if idChild is not 0.
If idChild <> 0 Then
Return Nothing
Else
Return New ConsoleProvider(hwnd)
End If
End Function
#Region "IRawElementProviderSimple"
End Function
Private Function GetPatternProvider(ByVal iid As Integer) As Object Implements
IRawElementProviderSimple.GetPatternProvider
Return Nothing
End Function
#End Region ' IRawElementProviderSimple
End Class
End Namespace
See Also
UI Automation Providers Overview
Register a Client-Side Provider Assembly
Implement UI Automation Providers in a Client
Application
4/14/2017 3 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic contains example code that shows how to implement a client-side UI Automation provider within an
application.
This is an uncommon scenario. Most often, a UI Automation client application uses server-side providers, or client-
side providers that reside in a DLL.
Example
The following example code implements a simple provider for a console window. The code does not have any
useful functionality, but is intended to demonstrate the basic steps in setting up a provider within client code and
registering it by using RegisterClientSideProviders.
using System;
using System.Windows.Automation;
using System.Windows.Automation.Provider;
using System.Reflection;
using System.Runtime.InteropServices;
using System.IO;
namespace CSClientProviderImplementation
{
class CSClientSideImplementationProgram
{
[DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow();
ClientSettings.RegisterClientSideProviders(
UIAutomationClientSideProviders.ClientSideProviderDescriptionTable);
class UIAutomationClientSideProviders
{
/// <summary>
/// Implementation of the static ClientSideProviderDescriptionTable field.
/// In this case,only a single provider is listed in the table.
/// </summary>
public static ClientSideProviderDescription[] ClientSideProviderDescriptionTable =
{ new ClientSideProviderDescription(
// Method that creates the provider object.
WindowProvider.Create,
// Class of window that will be served by the provider.
"ConsoleWindowClass") };
}
#region IRawElementProviderSimple
ProviderOptions IRawElementProviderSimple.ProviderOptions
{
get
{
return ProviderOptions.ClientSideProvider;
}
}
IRawElementProviderSimple IRawElementProviderSimple.HostRawElementProvider
{
get
{
return AutomationInteropProvider.HostProviderFromHandle(providerHwnd);
}
}
Imports System
Imports System.Windows.Automation
Imports System.Windows.Automation.Provider
Imports System.Reflection
Imports System.Runtime.InteropServices
Imports System.IO
Namespace CSClientProviderImplementation
Friend Class CSClientSideImplementationProgram
<DllImport("kernel32.dll")>
Shared Function GetConsoleWindow() As IntPtr
End Function
ClientSettings.RegisterClientSideProviders(UIAutomationClientSideProviders.ClientSideProviderDescriptionTable)
Friend Shared Function Create(ByVal hwnd As IntPtr, ByVal idChild As Integer, ByVal idObject As
Integer) As IRawElementProviderSimple
Return Create(hwnd, idChild)
End Function
#Region "IRawElementProviderSimple"
' This is a skeleton implementation. The only real functionality at this stage
' is to return the name of the element and the host window provider, which can
' supply other properties.
End Function
See Also
UI Automation Providers Overview
Register a Client-Side Provider Assembly
Create a Client-Side UI Automation Provider
Client-Side UI Automation Provider Implementation
UI Automation Clients for Managed Code
4/14/2017 1 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This section contains overviews and how-to topics to help you develop UI Automation clients.
In This Section
UI Automation and Screen Scaling
UI Automation Support for Standard Controls
UI Automation Events for Clients
Caching in UI Automation Clients
UI Automation Properties for Clients
Control Pattern Mapping for UI Automation Clients
UI Automation Control Patterns for Clients
Obtaining UI Automation Elements
UI Automation Threading Issues
How-to Topics
Reference
System.Windows.Automation
UI Automation and Screen Scaling
4/14/2017 4 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
Windows Vista enables users to change the dots per inch (dpi) setting so that most user interface (UI) elements on
the screen appear larger. Although this feature has long been available in Microsoft Windows, in previous versions
the scaling had to be implemented by applications. In Windows Vista, the Desktop Window Manager performs
default scaling for all applications that do not handle their own scaling. UI Automation client applications must take
this feature into account.
NOTE
By default, the DWM does not perform scaling for non-dpi-aware applications when the user sets the dpi to 120, but does
perform it when the dpi is set to a custom value of 144 or higher. However, the user can override the default behavior.
Screen scaling creates new challenges for applications that are concerned in any way with screen coordinates. The
screen now contains two coordinate systems: physical and logical. The physical coordinates of a point are the actual
offset in pixels from the top left of the origin. The logical coordinates are the offsets as they would be if the pixels
themselves were scaled.
Suppose you design a dialog box with a button at coordinates (100, 48). When this dialog box is displayed at the
default 96 dpi, the button is located at physical coordinates of (100, 48). At 120 dpi, it is located at physical
coordinates of (125, 60). But the logical coordinates are the same at any dpi setting: (100, 48).
Logical coordinates are important, because they make the behavior of the operating system and applications
consistent regardless of the dpi setting. For example, System.Windows.Forms.Cursor.Position normally returns the
logical coordinates. If you move the cursor over an element in a dialog box, the same coordinates are returned
regardless of the dpi setting. If you draw a control at (100, 100), it is drawn to those logical coordinates, and will
occupy the same relative position at any dpi setting.
[System.Runtime.InteropServices.DllImport("user32.dll")]
internal static extern bool SetProcessDPIAware();
<System.Runtime.InteropServices.DllImport("user32.dll")> _
Friend Shared Function SetProcessDPIAware() As Boolean
End Function
This function makes the entire process dpi-aware, meaning that all windows that belong to the process are
unscaled. In the Highlighter Sample, for instance, the four windows that make up the highlight rectangle are
located at the physical coordinates obtained from UI Automation, not the logical coordinates. If the sample
were not dpi-aware, the highlight would be drawn at the logical coordinates on the desktop, which would
result in incorrect placement in a non-96- dpi environment.
2. To get cursor coordinates, call the Win32 function GetPhysicalCursorPos . The following example shows how
to declare and use this function.
public struct CursorPoint
{
public int X;
public int Y;
}
[System.Runtime.InteropServices.DllImport("user32.dll")]
internal static extern bool GetPhysicalCursorPos(ref CursorPoint lpPoint);
Structure CursorPoint
Public X As Integer
Public Y As Integer
End Structure
<System.Runtime.InteropServices.DllImport("user32.dll")> _
Friend Shared Function GetPhysicalCursorPos(ByRef lpPoint As CursorPoint) As Boolean
End Function
End Function
Cau t i on
Do not use System.Windows.Forms.Cursor.Position. The behavior of this property outside client windows in a
scaled environment is undefined.
If your application performs direct cross-process communication with non- dpi-aware applications, you may have
convert between logical and physical coordinates by using the Win32 functions PhysicalToLogicalPoint and
LogicalToPhysicalPoint .
See Also
Highlighter Sample
UI Automation Support for Standard Controls
4/14/2017 2 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic contains information about Microsoft UI Automation support for standard controls in applications
developed for the WPF, Win32, and Windows Forms frameworks.
Win32 Controls
Most Win32 controls are exposed to Microsoft UI Automation through client-side providers in
UIAutomationClientsideProviders.dll. This assembly is automatically registered for use with UI Automation client
applications.
Full support is provided only for controls from version 6 of ComCtrl32.dll (available with Microsoft Windows XP
and later).
The following controls are supported.
Button Button
Button RadioButton
Button Group
Button CheckBox
Button Hyperlink
Button SplitButton
Button CheckBox
ComboBoxEx32 ComboBox
ComboBox ComboBox
Edit Document
CLASS NAME CONTROL TYPE
Edit Edit
SysLink Hyperlink
Static Text
Static Image
SysIPAddress32 Custom
SysHeader32 Header/HeaderItem
SysListView32 DataGrid
SysListView32 List
ListBox List
ListBox ListItem
#32768 Menu
#32768 MenuItem
msctls_progress32 ProgressBar
RichEdit20A Document
RichEdit20W Document
RichEdit50W Document
ScrollBar Slider
msctls_trackbar32 Slider
msctls_updown32 Spinner
msctls_statusbar32 StatusBar
SysTabControl32 Tab
SysTabControl32 TabItem
ToolbarWindow32 ToolBar
ToolbarWindow32 MenuItem
CLASS NAME CONTROL TYPE
ToolbarWindow32 Button
ToolbarWindow32 CheckBox
ToolbarWindow32 RadioButton
ToolbarWindow32 Separator
tooltips_class32 ToolTip
#32774 ToolTip
ReBarWindow32 Toolbar
SysTreeView32 Tree
SysTreeView32 TreeItem
Note The RichEdit control is supported only for versions shipped with Windows Vista (in RichEd20.dll version 3.1
and later, and MsftEdit.dll version 4.1 and later).
The following controls are not supported.
SysAnimate32 Image
SysPager Spinner
SysDateTimePick32 Custom
SysMonthCal32 Calendar
MS_WINNOTE Tooltip
VBBubble Tooltip
SuperGrid Custom
Button
CheckBox
CheckedListBox
ColorDialog
ComboBox
FolderBrowser
FontDialog
GroupBox
HscrollBar
ImageList
Label
ListBox
ListView
MainMenu/ContextMenu
MonthCalendar
NotifyIcon
OpenFileDialog
PageSetupDialog
PrintDialog
ProgressBar
RadioButton
RichTextBox
SaveFileDialog
ScrollableControl
SoundPlayer
CLASS NAME
StatusBar
TabControl/TabPage
TextBox
Timer
Toolbar
ToolTip
TrackBar
TreeView
VscrollBar
WebBrowser
The following controls are exposed to Microsoft UI Automation only through their support for Microsoft Active
Accessibility. Some functionality may not be available.
CONTROL NAME
BindingSource
DataGrid
DataGridView
DataNavigator
DomainUpDown
ErrorProvider
FlowLayoutPanel
Form
LinkLabel
HelpProvider
MaskedTextBox
MenuStrip/ContextMenuStrip
NumericUpDown
CONTROL NAME
Panel
PictureBox
PrintDocument
PrintPreview-Control
PrintPreview-Dialog
PropertyGrid
UserControl
ToolStrip
TableLayoutPanel
SplitContainer/SplitterPanel
Splitter
RaftingContainer
StatusStrip
See Also
UI Automation Control Types
UI Automation Events for Clients
4/14/2017 2 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic describes how Microsoft UI Automation events are used by UI Automation clients.
UI Automation allows clients to subscribe to events of interest. This capability improves performance by
eliminating the need to continually poll all the UI elements in the system to see if any information, structure, or
state has changed.
Efficiency is also improved by the ability to listen for events only within a defined scope. For example, a client can
listen for focus change events on all UI Automation elements in the tree, or on just one element and its
descendants.
NOTE
Do not assume that all possible events are raised by a Microsoft UI Automation provider. For example, not all property
changes cause events to be raised by the standard proxy providers for Windows Forms and Win32 controls.
Subscribing to Events
Client applications subscribe to events of a particular kind by registering an event handler, using one of the
following methods.
Before calling the method, you must create a delegate method to handle the event. If you prefer, you can handle
different kinds of events in a single method, and pass this method in multiple calls to one of the methods in the
table. For example, a single AutomationEventHandler can be set up to handle various events differently according
to the EventId.
NOTE
To process window-closed events, cast the argument type that is passed to the event handler as WindowClosedEventArgs.
Because the Microsoft UI Automation element for the window is no longer valid, you cannot use the sender parameter to
retrieve information; use GetRuntimeId instead.
Cau t i on
If your application might receive events from its own UI, do not use your application's UI thread to subscribe to
events, or to unsubscribe. Doing so might lead to unpredictable behavior. For more information, see UI
Automation Threading Issues.
On shutdown, or when UI Automation events are no longer of interest to the application, UI Automation clients
should call one of the following methods.
METHOD DESCRIPTION
See Also
Subscribe to UI Automation Events
UI Automation Events Overview
UI Automation Properties Overview
TrackFocus Sample
Caching in UI Automation Clients
5/31/2017 5 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
NOTE
You cannot cache parents or ancestors of the root element of the request.
See Also
UI Automation Events for Clients
Use Caching in UI Automation
FetchTimer Sample
UI Automation Properties for Clients
4/14/2017 4 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see
Windows Automation API: UI Automation.
This overview introduces you to UI Automation properties as they are exposed to UI Automation client
applications.
Properties on AutomationElement objects contain information about user interface (UI) elements, usually
controls. The properties of an AutomationElement are generic; that is, not specific to a control type. Many of
these properties are exposed in the AutomationElement.AutomationElementInformation structure.
Control patterns also have properties. The properties of control patterns are specific to the pattern. For
example, ScrollPattern has properties that enable a client application to discover whether a window is
vertically or horizontally scrollable, and what the current view sizes and scroll positions are. Control patterns
expose all their properties through a structure; for example, ScrollPattern.ScrollPatternInformation.
UI Automation properties are read-only. To set properties of a control, you must use the methods of the
appropriate control pattern. For example, use Scroll to change the position values of a scrolling window.
To improve performance, property values of controls and control patterns can be cached when
AutomationElement objects are retrieved. For more information, see Caching in UI Automation Clients.
Property IDs
Property identifiers (IDs) are unique, constant values that are encapsulated in AutomationProperty objects. UI
Automation client applications get these IDs from the AutomationElement class or from the appropriate
control pattern class, such as ScrollPattern. UI Automation providers get them from
AutomationElementIdentifiers or from one of the control pattern identifiers classes, such as
ScrollPatternIdentifiers.
The numeric Id of an AutomationProperty is used by providers to identify properties that are being queried
for in the System.Windows.Automation.Provider.IRawElementProviderSimple.GetPropertyValue method. In
general, client applications do not need to examine the Id. The ProgrammaticName is used only for
debugging and diagnostic purposes.
Property Conditions
The property IDs are used in constructing PropertyCondition objects used to find AutomationElement
objects. For example, you might wish to find an AutomationElement that has a certain name, or all controls
that are enabled. Each PropertyCondition specifies an AutomationProperty identifier and the value that the
property must match.
For more information, see the following reference topics:
FindFirst
FindAll
Condition
Retrieving Properties
Some properties of AutomationElement and all properties of a control pattern class are exposed as nested
properties of the Current or Cached property of the AutomationElement or control pattern object.
In addition, any AutomationElement or control pattern property, including a property that is not available in
the Cached or Current structure, can be retrieved by using one of the following methods:
GetCachedPropertyValue
GetCurrentPropertyValue
These methods offer slightly better performance as well as access to the full range of properties.
The following code example shows the two ways of retrieving a property on an AutomationElement.
// elementList is an AutomationElement.
To retrieve properties of control patterns supported by the AutomationElement, you do not need to retrieve
the control pattern object. Simply pass one of the pattern property identifiers to the method.
The following code example shows the two ways of retrieving a property on a control pattern.
SelectionPattern selectPattern =
elementList.GetCurrentPattern(SelectionPattern.Pattern) as SelectionPattern;
bool isMultipleSelect = selectPattern.Current.CanSelectMultiple;
The Get methods return an Object. The application must cast the returned object to the proper type before
using the value.
Default Property Values
If a UI Automation provider does not implement a property, the UI Automation system is able to supply a
default value. For example, if the provider for a control does not support the property identified by
HelpTextProperty, UI Automation returns an empty string. Similarly, if the provider does not support the
property identified by IsDockPatternAvailableProperty, UI Automation returns false .
You can change this behavior by using the
System.Windows.Automation.AutomationElement.GetCachedPropertyValue and
System.Windows.Automation.AutomationElement.GetCurrentPropertyValue method overloads. When you
specify true as the second parameter, UI Automation does not return a default value, but instead returns
the special value NotSupported.
The following example code attempts to retrieve a property from an element, and if the property is not
supported, an application-defined value is used instead.
// elementList is an AutomationElement.
object help = elementList.GetCurrentPropertyValue(AutomationElement.HelpTextProperty, true);
if (help == AutomationElement.NotSupported)
{
help = "No help available";
}
string helpText = (string)help;
To discover what properties are supported by an element, use GetSupportedProperties. This returns an array
of AutomationProperty identifiers.
Property-changed Events
When a property value on an AutomationElement or control pattern changes, an event is raised. An
application can subscribe to such events by calling AddAutomationPropertyChangedEventHandler, supplying
an array of AutomationProperty identifiers as the last parameter in order to specify the properties of interest.
In the AutomationPropertyChangedEventHandler, you can identify the property that has changed by
checking the Property member of the event arguments. The arguments also contain the old and new values
of the UI Automation property that has changed. These values are of type Object and must be cast to the
correct type before being used.
PROPERTY DESCRIPTION
See Also
Caching in UI Automation Clients
Server-Side UI Automation Provider Implementation
Subscribe to UI Automation Events
Control Pattern Mapping for UI Automation Clients
4/14/2017 2 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic lists control types and their associated control patterns.
The following table organizes the control patterns into the following categories:
Supported. The control must support this control pattern.
Conditional support. The control may support this control pattern depending on the state of the control.
Not supported. The control does not support this control pattern; custom controls may support this
control pattern.
NOTE
Some controls have conditional support for several control patterns depending on the functionality of the control. For
example, the menu item control has conditional support for the InvokePattern, ExpandCollapsePattern, TogglePattern, or
SelectionItemPattern control pattern, depending on its function in the menu control.
NOTE
If a control type has no supported control patterns listed but has one or more conditionally-supported control patterns,
then one of those conditional control patterns will be supported at all times.
See Also
UI Automation Overview
UI Automation Control Patterns for Clients
4/14/2017 2 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This overview introduces control patterns for UI Automation clients. It includes information on how a UI
Automation client can use control patterns to access information about the user interface (UI).
Control patterns provide a way to categorize and expose a control's functionality independent of the control
type or the appearance of the control. UI Automation clients can examine an AutomationElement to determine
which control patterns are supported and be assured of the behavior of the control.
For a complete list of control patterns, see UI Automation Control Patterns Overview.
// Specify the control type we're looking for, in this case 'Document'
PropertyCondition cond = new PropertyCondition(AutomationElement.ControlTypeProperty,
ControlType.Document);
if (targetTextPattern == null)
{
Console.WriteLine("Root element does not contain a descendant that supports TextPattern.");
return;
}
See Also
UI Automation Control Patterns
UI Automation Text Pattern
Invoke a Control Using UI Automation
Get the Toggle State of a Check Box Using UI Automation
Control Pattern Mapping for UI Automation Clients
TextPattern Insert Text Sample
TextPattern Search and Selection Sample
InvokePattern and ExpandCollapsePattern Menu Item Sample
Obtaining UI Automation Elements
4/14/2017 4 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic describes the various ways of obtaining AutomationElement objects for user interface (UI) elements.
Cau t i on
If your client application might attempt to find elements in its own user interface, you must make all UI
Automation calls on a separate thread. For more information, see UI Automation Threading Issues.
Root Element
All searches for AutomationElement objects must have a starting-place. This can be any element, including the
desktop, an application window, or a control.
The root element for the desktop, from which all elements are descended, is obtained from the static
System.Windows.Automation.AutomationElement.RootElement property.
Cau t i on
In general, you should try to obtain only direct children of the RootElement. A search for descendants may 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.
Conditions
For most techniques you can use to retrieve UI Automation elements, you must specify a Condition, which is a set
of criteria defining what elements you want to retrieve.
The simplest condition is TrueCondition, a predefined object specifying that all elements within the search scope
are to be returned. FalseCondition, the converse of TrueCondition, is less useful, as it would prevent any elements
from being found.
Three other predefined conditions can be used alone or in combination with other conditions:
ContentViewCondition, ControlViewCondition, and RawViewCondition. RawViewCondition, used by itself, is
equivalent to TrueCondition, because it does not filter elements by their IsControlElement or IsContentElement
properties.
Other conditions are built up from one or more PropertyCondition objects, each of which specifies a property
value. For example, a PropertyCondition might specify that the element is enabled, or that it supports a certain
control pattern.
Conditions can be combined using Boolean logic by constructing objects of types AndCondition, OrCondition, and
NotCondition.
Search Scope
Searches done by using FindFirst or FindAll must have a scope as well as a starting-place.
The scope defines the space around the starting-place that is to be searched. This might include the element itself,
its siblings, its parent, its ancestors, its immediate children, and its descendants.
The scope of a search is defined by a bitwise combination of values from the TreeScope enumeration.
Walking a Subtree
If you have no prior knowledge of the applications that your client may be used with, you can construct a subtree
of all elements of interest by using the TreeWalker class. Your application might do this in response to a focus-
changed event; that is, when an application or control receives input focus, the UI Automation client examines
children and perhaps all descendants of the focused element.
Another way in which TreeWalker can be used is to identify the ancestors of an element. For example, by walking
up the tree you can identify the parent window of a control.
You can use TreeWalker either by creating an object of the class (defining the elements of interest by passing a
Condition), or by using one of the following predefined objects that are defined as fields of TreeWalker.
After you have obtained a TreeWalker, using it is straightforward. Simply call the Get methods to navigate among
elements of the subtree.
The Normalize method can be used for navigating to an element in the subtree from another element that is not
part of the view. For example, suppose you have created a view of a subtree by using ContentViewWalker. Your
application then receives notification that a scroll bar has received the input focus. Because a scroll bar is not a
content element, it is not present in your view of the subtree. However, you can pass the AutomationElement
representing the scroll bar to Normalize and retrieve the nearest ancestor that is in the content view.
See Also
Find a UI Automation Element Based on a Property Condition
Navigate Among UI Automation Elements with TreeWalker
UI Automation Tree Overview
UI Automation Threading Issues
4/14/2017 1 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
Because of the way Microsoft UI Automation uses Windows messages, conflicts can occur when a client
application attempts to interact with its own UI on the UI thread. These conflicts can lead to very slow performance
or even cause the application to stop responding.
If your client application is intended to interact with all elements on the desktop, including its own UI, you should
make all UI Automation calls on a separate thread. This includes locating elements (for example, by using
TreeWalker or the FindAll method) and using control patterns.
It is safe to make UI Automation calls within a UI Automation event handler, because the event handler is always
called on a non-UI thread. However, when subscribing to events that may originate from your client application's
UI, you must make the call to AddAutomationEventHandler, or a related method, on a non-UI thread. Remove
event handlers on the same thread.
UI Automation Clients for Managed Code How-to
Topics
4/14/2017 1 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This section provides detailed information about implementing features of Microsoft UI Automation in a client
application.
In This Section
Find a UI Automation Element Based on a Property Condition
Navigate Among UI Automation Elements with TreeWalker
Find a UI Automation Element for a List Item
Get UI Automation Element Properties
Use Caching in UI Automation
Subscribe to UI Automation Events
Register a Client-Side Provider Assembly
Use the AutomationID Property
Find a UI Automation Element Based on a Property
Condition
4/14/2017 5 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic contains example code that shows how to locate an element within the UI Automation tree based on a
specific property or properties.
Example
In the following example, a set of property conditions are specified that identify a certain element (or elements) of
interest in the AutomationElement tree. A search for all matching elements is then performed with the FindAll
method that incorporates a series of AndCondition boolean operations to limit the number of matching elements.
NOTE
When searching from the RootElement, 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.
///--------------------------------------------------------------------
/// <summary>
/// Walks the UI Automation tree of the target and reports the control
/// type of each element it finds in the control view to the client.
/// </summary>
/// <param name="targetTreeViewElement">
/// The root of the search on this iteration.
/// </param>
/// <param name="elementIndex">
/// The TreeView index for this iteration.
/// </param>
/// <remarks>
/// This is a recursive function that maps out the structure of the
/// subtree of the target beginning at the AutomationElement passed in
/// as the rootElement on the first call. This could be, for example,
/// an application window.
/// CAUTION: Do not pass in AutomationElement.RootElement. Attempting
/// to map out the entire subtree of the desktop could take a very
/// long time and even lead to a stack overflow.
/// </remarks>
///--------------------------------------------------------------------
private void FindTreeViewDescendants(
AutomationElement targetTreeViewElement, int treeviewIndex)
{
if (targetTreeViewElement == null)
return;
AutomationElement elementNode =
AutomationElement elementNode =
TreeWalker.ControlViewWalker.GetFirstChild(targetTreeViewElement);
elementInfoCompile.Append(controlName)
.Append(" (")
.Append(elementNode.Current.ControlType.LocalizedControlType)
.Append(" - ")
.Append(autoIdName)
.Append(")");
'''--------------------------------------------------------------------
''' <summary>
''' Walks the UI Automation tree of the target and reports the control
''' type of each element it finds in the control view to the client.
''' </summary>
''' <param name="targetTreeViewElement">
''' The root of the search on this iteration.
''' </param>
''' <param name="treeviewIndex">
''' The TreeView index for this iteration.
''' </param>
''' <remarks>
''' This is a recursive function that maps out the structure of the
''' subtree beginning at the AutomationElement passed in as
''' rootElement on the first call. This could be, for example,
''' an application window.
''' CAUTION: Do not pass in AutomationElement.RootElement. Attempting
''' to map out the entire subtree of the desktop could take a very
''' long time and even lead to a stack overflow.
''' </remarks>
'''--------------------------------------------------------------------
Private Sub FindTreeViewDescendants( _
ByVal targetTreeViewElement As AutomationElement, _
ByVal treeviewIndex As Integer)
If (IsNothing(targetTreeViewElement)) Then
Return
End If
elementInfoCompile.Append(controlName).Append(" (") _
elementInfoCompile.Append(controlName).Append(" (") _
.Append(elementNode.Current.ControlType.LocalizedControlType) _
.Append(" - ").Append(autoIdName).Append(")")
' Test for the control patterns of interest for this sample.
Dim objPattern As Object = Nothing
Dim expcolPattern As ExpandCollapsePattern
If True = elementNode.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, objPattern) Then
expcolPattern = DirectCast(objPattern, ExpandCollapsePattern)
If expcolPattern.Current.ExpandCollapseState <> ExpandCollapseState.LeafNode Then
Dim expcolButton As New Button()
expcolButton.Margin = New Thickness(0, 0, 0, 5)
expcolButton.Height = 20
expcolButton.Width = 100
expcolButton.Content = "ExpandCollapse"
expcolButton.Tag = expcolPattern
AddHandler expcolButton.Click, AddressOf ExpandCollapse_Click
clientTreeViews(treeviewIndex).Children.Add(expcolButton)
End If
End If
Dim togPattern As TogglePattern
If True = elementNode.TryGetCurrentPattern(TogglePattern.Pattern, objPattern) Then
togPattern = DirectCast(objPattern, TogglePattern)
Dim togButton As New Button()
togButton.Margin = New Thickness(0, 0, 0, 5)
togButton.Height = 20
togButton.Width = 100
togButton.Content = "Toggle"
togButton.Tag = togPattern
AddHandler togButton.Click, AddressOf Toggle_Click
clientTreeViews(treeviewIndex).Children.Add(togButton)
End If
Dim invPattern As InvokePattern
If True = elementNode.TryGetCurrentPattern(InvokePattern.Pattern, objPattern) Then
invPattern = DirectCast(objPattern, InvokePattern)
Dim invButton As New Button()
invButton.Margin = New Thickness(0)
invButton.Height = 20
invButton.Width = 100
invButton.Content = "Invoke"
invButton.Tag = invPattern
AddHandler invButton.Click, AddressOf Invoke_Click
clientTreeViews(treeviewIndex).Children.Add(invButton)
End If
' Display compiled information about the control.
elementInfo.Content = elementInfoCompile
Dim sep As New Separator()
clientTreeViews(treeviewIndex).Children.Add(sep)
See Also
InvokePattern and ExpandCollapsePattern Menu Item Sample
Obtaining UI Automation Elements
Use the AutomationID Property
Navigate Among UI Automation Elements with
TreeWalker
4/14/2017 3 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic contains example code that shows how to navigate among Microsoft UI Automation elements by using
the TreeWalker class.
Example
The following example uses GetParent to walk up the Microsoft UI Automation tree until it finds the root element,
or desktop. The element just below that is the parent window of the specified element.
/// <summary>
/// Retrieves the top-level window that contains the specified UI Automation element.
/// </summary>
/// <param name="element">The contained element.</param>
/// <returns>The containing top-level window element.</returns>
private AutomationElement GetTopLevelWindow(AutomationElement element)
{
TreeWalker walker = TreeWalker.ControlViewWalker;
AutomationElement elementParent;
AutomationElement node = element;
if (node == elementRoot) return node;
do
{
elementParent = walker.GetParent(node);
if (elementParent == AutomationElement.RootElement) break;
node = elementParent;
}
while (true);
return node;
}
''' <summary>
''' Retrieves the top-level window that contains the specified UI Automation element.
''' </summary>
''' <param name="element">The contained element.</param>
''' <returns>The containing top-level window element.</returns>
Private Function GetTopLevelWindow(ByVal element As AutomationElement) As AutomationElement
Dim walker As TreeWalker = TreeWalker.ControlViewWalker
Dim elementParent As AutomationElement
Dim node As AutomationElement = element
If node = elementRoot Then
Return node
End If
Do
elementParent = walker.GetParent(node)
If elementParent = AutomationElement.RootElement Then
Exit Do
End If
node = elementParent
Loop While True
Return node
Example
The following example uses GetFirstChild and GetNextSibling to create a TreeView that shows an entire subtree of
Microsoft UI Automation elements that are in the control view and that are enabled.
/// <summary>
/// Walks the UI Automation tree and adds the control type of each enabled control
/// element it finds to a TreeView.
/// </summary>
/// <param name="rootElement">The root of the search on this iteration.</param>
/// <param name="treeNode">The node in the TreeView for this iteration.</param>
/// <remarks>
/// This is a recursive function that maps out the structure of the subtree beginning at the
/// UI Automation element passed in as rootElement on the first call. This could be, for example,
/// an application window.
/// CAUTION: Do not pass in AutomationElement.RootElement. Attempting to map out the entire subtree of
/// the desktop could take a very long time and even lead to a stack overflow.
/// </remarks>
private void WalkEnabledElements(AutomationElement rootElement, TreeNode treeNode)
{
Condition condition1 = new PropertyCondition(AutomationElement.IsControlElementProperty, true);
Condition condition2 = new PropertyCondition(AutomationElement.IsEnabledProperty, true);
TreeWalker walker = new TreeWalker(new AndCondition(condition1, condition2));
AutomationElement elementNode = walker.GetFirstChild(rootElement);
while (elementNode != null)
{
TreeNode childTreeNode = treeNode.Nodes.Add(elementNode.Current.ControlType.LocalizedControlType);
WalkEnabledElements(elementNode, childTreeNode);
elementNode = walker.GetNextSibling(elementNode);
}
}
''' <summary>
''' Walks the UI Automation tree and adds the control type of each enabled control
''' element it finds to a TreeView.
''' </summary>
''' <param name="rootElement">The root of the search on this iteration.</param>
''' <param name="treeNode">The node in the TreeView for this iteration.</param>
''' <remarks>
''' This is a recursive function that maps out the structure of the subtree beginning at the
''' UI Automation element passed in as rootElement on the first call. This could be, for example,
''' an application window.
''' CAUTION: Do not pass in AutomationElement.RootElement. Attempting to map out the entire subtree of
''' the desktop could take a very long time and even lead to a stack overflow.
''' </remarks>
Private Sub WalkEnabledElements(ByVal rootElement As AutomationElement, ByVal treeNode As TreeNode)
Dim condition1 As New PropertyCondition(AutomationElement.IsControlElementProperty, True)
Dim condition2 As New PropertyCondition(AutomationElement.IsEnabledProperty, True)
Dim walker As New TreeWalker(New AndCondition(condition1, condition2))
Dim elementNode As AutomationElement = walker.GetFirstChild(rootElement)
While (elementNode IsNot Nothing)
Dim childTreeNode As TreeNode =
treeNode.Nodes.Add(elementNode.Current.ControlType.LocalizedControlType)
WalkEnabledElements(elementNode, childTreeNode)
elementNode = walker.GetNextSibling(elementNode)
End While
See Also
Obtaining UI Automation Elements
Find a UI Automation Element for a List Item
4/14/2017 2 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes defined
in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows Automation
API: UI Automation.
This topic shows how to retrieve an AutomationElement for an item within a list when the index of the item is
known.
Example
The following example shows two ways of retrieving a specified item from a list, one using TreeWalker and the
other using FindAll.
The first technique tends to be faster for Win32 controls, but the second is faster for Windows Presentation
Foundation (WPF) controls.
/// <summary>
/// Retrieves an element in a list, using TreeWalker.
/// </summary>
/// <param name="parent">The list element.</param>
/// <param name="index">The index of the element to find.</param>
/// <returns>The list item.</returns>
AutomationElement FindChildAt(AutomationElement parent, int index)
{
if (index < 0)
{
throw new ArgumentOutOfRangeException();
}
TreeWalker walker = TreeWalker.ControlViewWalker;
AutomationElement child = walker.GetFirstChild(parent);
for (int x = 1; x <= index; x++)
{
child = walker.GetNextSibling(child);
if (child == null)
{
throw new ArgumentOutOfRangeException();
}
}
return child;
}
/// <summary>
/// Retrieves an element in a list, using FindAll.
/// </summary>
/// <param name="parent">The list element.</param>
/// <param name="index">The index of the element to find.</param>
/// <returns>The list item.</returns>
AutomationElement FindChildAtB(AutomationElement parent, int index)
{
Condition findCondition = new PropertyCondition(AutomationElement.IsControlElementProperty, true);
AutomationElementCollection found = parent.FindAll(TreeScope.Children, findCondition);
if ((index < 0) || (index >= found.Count))
{
throw new ArgumentOutOfRangeException();
}
return found[index];
}
''' <summary>
''' Retrieves an element in a list, using TreeWalker.
''' </summary>
''' <param name="parent">The list element.</param>
''' <param name="index">The index of the element to find.</param>
''' <returns>The list item.</returns>
Function FindChildAt(ByVal parent As AutomationElement, ByVal index As Integer) As AutomationElement
''' <summary>
''' Retrieves an element in a list, using FindAll.
''' </summary>
''' <param name="parent">The list element.</param>
''' <param name="index">The index of the element to find.</param>
''' <returns>The list item.</returns>
Function FindChildAtB(ByVal parent As AutomationElement, ByVal index As Integer) As AutomationElement
Dim findCondition As Condition = _
New PropertyCondition(AutomationElement.IsControlElementProperty, True)
Dim found As AutomationElementCollection = parent.FindAll(TreeScope.Children, findCondition)
If (index < 0) Or (index >= found.Count) Then
Throw New ArgumentOutOfRangeException()
End If
Return found(index)
End Function
See Also
Obtaining UI Automation Elements
Get UI Automation Element Properties
4/14/2017 1 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes defined
in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows Automation
API: UI Automation.
Example
The following example shows various ways to retrieve current properties of an AutomationElement.
' The following shows how to ignore the default property, which
' would probably be an empty string if the property is not supported.
' Passing "false" as the second parameter is equivalent to using the overload
' that does not have this parameter.
Dim help As Object = elementList.GetCurrentPropertyValue(AutomationElement.HelpTextProperty, True)
If help Is AutomationElement.NotSupported Then
help = "No help available"
End If
Dim helpText As String = CStr(help)
See Also
UI Automation Properties for Clients
Use Caching in UI Automation
Caching in UI Automation Clients
Use Caching in UI Automation
5/31/2017 7 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This section shows how to implement caching of AutomationElement properties and control patterns.
Activate a Cache Request
1. Create a CacheRequest.
2. Specify properties and patterns to cache by using Add.
3. Specify the scope of caching by setting the TreeScope property.
4. Specify the view of the subtree by setting the TreeFilter property.
5. Set the AutomationElementMode property to None if you wish to increase efficiency by not retrieving a
full reference to objects. (This will make it impossible to retrieve current values from those objects.)
6. Activate the request by using Activate within a using block ( Using in Microsoft Visual Basic .NET).
After obtaining AutomationElement objects or subscribing to events, deactivate the request by using Pop (if
Push was used) or by disposing the object created by Activate. (Use Activate in a using block ( Using in
Microsoft Visual Basic .NET).
Cache AutomationElement Properties
1. While a CacheRequest is active, obtain AutomationElement objects by using FindFirst or FindAll; or obtain
an AutomationElement as the source of an event that you registered for when the CacheRequest was
active. (You can also create a cache by passing a CacheRequest to GetUpdatedCache or one of the
TreeWalker methods.)
2. Use GetCachedPropertyValue or retrieve a property from the Cached property of the AutomationElement.
Obtain Cached Patterns and Their Properties
1. While a CacheRequest is active, obtain AutomationElement objects by using FindFirst or FindAll; or obtain
an AutomationElement as the source of an event that you registered for when the CacheRequest was
active. (You can also create a cache by passing a CacheRequest to GetUpdatedCache or one of the
TreeWalker methods.)
2. Use GetCachedPattern or TryGetCachedPattern to retrieve a cached pattern.
3. Retrieve property values from the Cached property of the control pattern.
Example
The following code example shows various aspects of caching, using Activate to activate the CacheRequest.
/// <summary>
/// Caches and retrieves properties for a list item by using CacheRequest.Activate.
/// </summary>
/// <param name="elementList">Element from which to retrieve a child element.</param>
/// <remarks>
/// This code demonstrates various aspects of caching. It is not intended to be
/// an example of a useful method.
/// </remarks>
private void CachePropertiesByActivate(AutomationElement elementList)
{
AutomationElement elementListItem;
// The following line will raise an exception, because the HelpText property was not cached.
/*** String itemHelp = elementListItem.Cached.HelpText; ***/
// Similarly, pattern properties that were not specified in the CacheRequest cannot be
// retrieved from the cache. This would raise an exception.
/*** bool selected = pattern.Cached.IsSelected; ***/
// This is still a valid call, even though the property is in the cache.
// Of course, the cached value and the current value are not guaranteed to be the same.
itemName = elementListItem.Current.Name;
}
''' <summary>
''' Caches and retrieves properties for a list item by using CacheRequest.Activate.
''' </summary>
''' <param name="elementList">Element from which to retrieve a child element.</param>
''' <remarks>
''' This code demonstrates various aspects of caching. It is not intended to be
''' an example of a useful method.
''' </remarks>
Private Sub CachePropertiesByActivate(ByVal elementList As AutomationElement)
' The following line will raise an exception, because the HelpText property was not cached.
'** String itemHelp = elementListItem.Cached.HelpText; **
' Similarly, pattern properties that were not specified in the CacheRequest cannot be
' retrieved from the cache. This would raise an exception.
'** bool selected = pattern.Cached.IsSelected; **
' This is still a valid call, even though the property is in the cache.
' Of course, the cached value and the current value are not guaranteed to be the same.
itemName = elementListItem.Current.Name
End Sub 'CachePropertiesByActivate
Example
The following code example shows various aspects of caching, using Push to activate the CacheRequest. Except
when you wish to nest cache requests, it is preferable to use Activate.
/// <summary>
/// Caches and retrieves properties for a list item by using CacheRequest.Push.
/// </summary>
/// <param name="autoElement">Element from which to retrieve a child element.</param>
/// <remarks>
/// This code demonstrates various aspects of caching. It is not intended to be
/// an example of a useful method.
/// </remarks>
private void CachePropertiesByPush(AutomationElement elementList)
{
// Set up the request.
CacheRequest cacheRequest = new CacheRequest();
// Do not get a full reference to the cached objects, only to their cached properties and patterns.
cacheRequest.AutomationElementMode = AutomationElementMode.None;
// Cache all elements, regardless of whether they are control or content elements.
cacheRequest.TreeFilter = Automation.RawViewCondition;
// At this point, you could call another method that creates a CacheRequest and calls Push/Pop.
// While that method was retrieving automation elements, the CacheRequest set in this method
// would not be active.
// This is yet another way, which returns AutomationElement.NotSupported if the element does
// not supply a value. If the second parameter is false, a default name is returned.
object objName = elementListItem.GetCachedPropertyValue(AutomationElement.NameProperty, true);
if (objName == AutomationElement.NotSupported)
{
itemName = "Unknown";
}
else
{
itemName = objName as String;
}
// The following call raises an exception, because only the cached properties are available,
// as specified by cacheRequest.AutomationElementMode. If AutomationElementMode had its
// default value (Full), this call would be valid.
/*** bool enabled = elementListItem.Current.IsEnabled; ***/
}
''' <summary>
''' Caches and retrieves properties for a list item by using CacheRequest.Push.
''' </summary>
''' <param name="elementList">Element from which to retrieve a child element.</param>
''' <remarks>
''' This code demonstrates various aspects of caching. It is not intended to be
''' an example of a useful method.
''' </remarks>
Private Sub CachePropertiesByPush(ByVal elementList As AutomationElement)
' Set up the request.
Dim cacheRequest As New CacheRequest()
' Do not get a full reference to the cached objects, only to their cached properties and patterns.
cacheRequest.AutomationElementMode = AutomationElementMode.None
' Cache all elements, regardless of whether they are control or content elements.
cacheRequest.TreeFilter = Automation.RawViewCondition
' At this point, you could call another method that creates a CacheRequest and calls Push/Pop.
' While that method was retrieving automation elements, the CacheRequest set in this method
' would not be active.
' Deactivate the request.
cacheRequest.Pop()
' This is yet another way, which returns AutomationElement.NotSupported if the element does
' not supply a value. If the second parameter is false, a default name is returned.
Dim objName As Object = elementListItem.GetCachedPropertyValue(AutomationElement.NameProperty, True)
If objName Is AutomationElement.NotSupported Then
itemName = "Unknown"
Else
itemName = CStr(objName)
End If
' The following call raises an exception, because only the cached properties are available,
' as specified by cacheRequest.AutomationElementMode. If AutomationElementMode had its
' default value (Full), this call would be valid.
'** bool enabled = elementListItem.Current.IsEnabled; **
See Also
Caching in UI Automation Clients
Subscribe to UI Automation Events
4/14/2017 3 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
Example
The following example code registers an event handler for the event that is raised when a control such as a button
is invoked, and removes it when the application form closes. The event is identified by an AutomationEvent passed
as a parameter to AddAutomationEventHandler.
// Member variables.
AutomationElement ElementSubscribeButton;
AutomationEventHandler UIAeventHandler;
/// <summary>
/// Register an event handler for InvokedEvent on the specified element.
/// </summary>
/// <param name="elementButton">The automation element.</param>
public void SubscribeToInvoke(AutomationElement elementButton)
{
if (elementButton != null)
{
Automation.AddAutomationEventHandler(InvokePattern.InvokedEvent,
elementButton, TreeScope.Element,
UIAeventHandler = new AutomationEventHandler(OnUIAutomationEvent));
ElementSubscribeButton = elementButton;
}
}
/// <summary>
/// AutomationEventHandler delegate.
/// </summary>
/// <param name="src">Object that raised the event.</param>
/// <param name="e">Event arguments.</param>
private void OnUIAutomationEvent(object src, AutomationEventArgs e)
{
// Make sure the element still exists. Elements such as tooltips
// can disappear before the event is processed.
AutomationElement sourceElement;
try
{
sourceElement = src as AutomationElement;
}
catch (ElementNotAvailableException)
{
return;
}
if (e.EventId == InvokePattern.InvokedEvent)
{
// TODO Add handling code.
}
else
{
// TODO Handle any other events that have been subscribed to.
}
}
''' <summary>
''' Register an event handler for InvokedEvent on the specified element.
''' </summary>
''' <param name="elementButton">The automation element.</param>
Public Sub SubscribeToInvoke(ByVal elementButton As AutomationElement)
If (elementButton IsNot Nothing) Then
UIAeventHandler = New AutomationEventHandler(AddressOf OnUIAutomationEvent)
Automation.AddAutomationEventHandler(InvokePattern.InvokedEvent, elementButton, _
TreeScope.Element, UIAeventHandler)
ElementSubscribeButton = elementButton
End If
''' <summary>
''' AutomationEventHandler delegate.
''' </summary>
''' <param name="src">Object that raised the event.</param>
''' <param name="e">Event arguments.</param>
Private Sub OnUIAutomationEvent(ByVal src As Object, ByVal e As AutomationEventArgs)
' Make sure the element still exists. Elements such as tooltips can disappear
' before the event is processed.
Dim sourceElement As AutomationElement
Try
sourceElement = DirectCast(src, AutomationElement)
Catch ex As ElementNotAvailableException
Exit Sub
End Try
If e.EventId Is InvokePattern.InvokedEvent Then
' TODO Add handling code.
Else
End If
' TODO Handle any other events that have been subscribed to.
Console.WriteLine("Event: " & e.EventId.ProgrammaticName)
End Sub 'OnUIAutomationEvent
Example
The following example shows how to use Microsoft UI Automation to subscribe to an event that is raised when the
focus changes. The event handler is unregistered in a method that could be called on application shutdown, or
when notification of UI events is no longer required.
AutomationFocusChangedEventHandler focusHandler = null;
/// <summary>
/// Create an event handler and register it.
/// </summary>
public void SubscribeToFocusChange()
{
focusHandler = new AutomationFocusChangedEventHandler(OnFocusChange);
Automation.AddAutomationFocusChangedEventHandler(focusHandler);
}
/// <summary>
/// Handle the event.
/// </summary>
/// <param name="src">Object that raised the event.</param>
/// <param name="e">Event arguments.</param>
private void OnFocusChange(object src, AutomationFocusChangedEventArgs e)
{
// TODO Add event handling code.
// The arguments tell you which elements have lost and received focus.
}
/// <summary>
/// Cancel subscription to the event.
/// </summary>
public void UnsubscribeFocusChange()
{
if (focusHandler != null)
{
Automation.RemoveAutomationFocusChangedEventHandler(focusHandler);
}
}
Private focusHandler As AutomationFocusChangedEventHandler = Nothing
''' <summary>
''' Create an event handler and register it.
''' </summary>
Public Sub SubscribeToFocusChange()
focusHandler = New AutomationFocusChangedEventHandler(AddressOf OnFocusChange)
Automation.AddAutomationFocusChangedEventHandler(focusHandler)
''' <summary>
''' Handle the event.
''' </summary>
''' <param name="src">Object that raised the event.</param>
''' <param name="e">Event arguments.</param>
Private Sub OnFocusChange(ByVal src As Object, ByVal e As AutomationFocusChangedEventArgs)
''' <summary>
''' Cancel subscription to the event.
''' </summary>
Public Sub UnsubscribeFocusChange()
If (focusHandler IsNot Nothing) Then
Automation.RemoveAutomationFocusChangedEventHandler(focusHandler)
End If
See Also
AddAutomationEventHandler
RemoveAllEventHandlers
RemoveAutomationEventHandler
UI Automation Events Overview
Register a Client-Side Provider Assembly
4/14/2017 1 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic shows how to register a DLL that contains client-side UI Automation providers.
Example
The following example shows how to register an assembly that contains a provider for a console window.
using System;
using System.Windows.Automation;
using System.Reflection;
using System.Runtime.InteropServices;
using System.IO;
namespace CSClient
{
class CSClientProgram
{
[DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow();
}
if (a != null)
{
try
{
ClientSettings.RegisterClientSideProviderAssembly(a.GetName());
}
catch (ProxyAssemblyNotLoadedException e)
{
Console.WriteLine(e.Message);
}
Namespace CSClient
Friend Class CSClientProgram
<DllImport("kernel32.dll")>
Shared Function GetConsoleWindow() As IntPtr
End Function
End Try
If a IsNot Nothing Then
Try
ClientSettings.RegisterClientSideProviderAssembly(a.GetName())
Catch e As ProxyAssemblyNotLoadedException
Console.WriteLine(e.Message)
End Try
See Also
Create a Client-Side UI Automation Provider
Use the AutomationID Property
4/14/2017 9 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic contains scenarios and sample code that show how and when the AutomationIdProperty can be used to
locate an element within the UI Automation tree.
AutomationIdProperty uniquely identifies a UI Automation element from its siblings. For more information on
property identifiers related to control identification, see UI Automation Properties Overview.
NOTE
AutomationIdProperty does not guarantee a unique identity throughout the tree; it typically needs container and scope
information to be useful. For example, an application may contain a menu control with multiple top-level menu items that, in
turn, have multiple child menu items. These secondary menu items may be identified by a generic scheme such as "Item1",
"Item 2", and so on, allowing duplicate identifiers for children across top-level menu items.
Scenarios
Three primary UI Automation client application scenarios have been identified that require the use of
AutomationIdProperty to achieve accurate and consistent results when searching for elements.
NOTE
AutomationIdProperty is supported by all UI Automation elements in the control view except top-level application windows,
UI Automation elements derived from Windows Presentation Foundation (WPF) controls that do not have an ID or x:Uid,
and UI Automation elements derived from Win32 controls that do not have a control ID.
Use a unique and discoverable AutomationID to locate a specific element in the UI Automation tree
Use a tool such as UI Spy to report the AutomationIdProperty of a UI element of interest. This value can then be
copied and pasted into a client application such as a test script for subsequent automated testing. This approach
reduces and simplifies the code necessary to identify and locate an element at runtime.
Cau t i on
In general, you should try to obtain only direct children of the RootElement. A search for descendants may 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.
///--------------------------------------------------------------------
/// <summary>
/// Finds all elements in the UI Automation tree that have a specified
/// AutomationID.
/// </summary>
/// <param name="targetApp">
/// The root element from which to start searching.
/// </param>
/// <param name="automationID">
/// The AutomationID value of interest.
/// </param>
/// <returns>
/// The collection of UI Automation elements that have the specified
/// AutomationID value.
/// </returns>
///--------------------------------------------------------------------
private AutomationElementCollection FindElementFromAutomationID(AutomationElement targetApp,
string automationID)
{
return targetApp.FindAll(
TreeScope.Descendants,
new PropertyCondition(AutomationElement.AutomationIdProperty, automationID));
}
'''--------------------------------------------------------------------
''' <summary>
''' Finds all elements in the UI Automation tree that have a specified
''' AutomationID.
''' </summary>
''' <param name="targetApp">
''' The root element from which to start searching.
''' </param>
''' <param name="automationID">
''' The AutomationID value of interest.
''' </param>
''' <returns>
''' The collection of automation elements that have the specified
''' AutomationID value.
''' </returns>
'''--------------------------------------------------------------------
Private Function FindElementFromAutomationID( _
ByVal targetApp As AutomationElement, _
ByVal automationID As String) As AutomationElementCollection
Return targetApp.FindAll( _
TreeScope.Descendants, _
New PropertyCondition( _
AutomationElement.AutomationIdProperty, automationID))
End Function 'FindElementFromAutomationID
///--------------------------------------------------------------------
/// <summary>
/// Delegated method for ThreadStart. Creates a UI Automation worker
/// class that does all UI Automation related work.
/// </summary>
///--------------------------------------------------------------------
public void CreateUIAWorker()
{
uiautoWorker = new FindByAutomationID(targetApp);
}
private FindByAutomationID uiautoWorker;
'''--------------------------------------------------------------------
''' <summary>
''' Creates a UI Automation thread.
''' </summary>
''' <param name="sender">Object that raised the event.</param>
''' <param name="e">Event arguments.</param>
''' <remarks>
''' UI Automation must be called on a separate thread if the client
''' application itself could become a target for event handling.
''' For example, focus tracking is a desktop event that could involve
''' the client application.
''' </remarks>
'''--------------------------------------------------------------------
Private Sub CreateUIAThread(ByVal sender As Object, ByVal e As EventArgs)
'''--------------------------------------------------------------------
''' <summary>
''' Delegated method for ThreadStart. Creates a UI Automation worker
''' class that does all UI Automation related work.
''' </summary>
'''--------------------------------------------------------------------
Public Sub CreateUIAWorker()
///--------------------------------------------------------------------
/// <summary>
/// Function to playback through a series of recorded events calling
/// a WriteToScript function for each event of interest.
/// </summary>
/// <remarks>
/// A major drawback to using AutomationID for recording user
/// interactions in a volatile UI is the probability of catastrophic
/// change in the UI. For example, the //Processes// dialog where items
/// in the listbox container can change with no input from the user.
/// This mandates thtat a record and playback application must be
/// reliant on the tester owning the UI being tested. In other words,
/// there has to be a contract between the provider and client that
/// excludes uncontrolled, external applications. The added benefit
/// is the guarantee that each control in the UI should have an
/// AutomationID assigned to it.
///
/// This function relies on a UI Automation worker class to create
/// the System.Collections.Generic.Queue object that stores the
/// information for the recorded user interactions. This
/// allows post-processing of the recorded items prior to actually
/// writing them to a script. If this is not necessary the interaction
/// could be written to the script immediately.
/// </remarks>
///--------------------------------------------------------------------
private void Playback(AutomationElement targetApp)
{
AutomationElement element;
foreach(ElementStore storedItem in uiautoWorker.elementQueue)
{
PropertyCondition propertyCondition =
new PropertyCondition(
AutomationElement.AutomationIdProperty, storedItem.AutomationID);
// Confirm the existence of a control.
// Depending on the controls and complexity of interaction
// this step may not be necessary or may require additional
// functionality. For example, to confirm the existence of a
// child menu item that had been invoked the parent menu item
// would have to be expanded.
element = targetApp.FindFirst(TreeScope.Descendants, propertyCondition);
if(element == null)
{
// Control not available, unable to continue.
// TODO: Handle error condition.
return;
}
WriteToScript(storedItem.AutomationID, storedItem.EventID);
}
}
///--------------------------------------------------------------------
/// <summary>
/// Generates script code and outputs the code to a text control in
/// the client.
/// </summary>
/// <param name="automationID">
/// The AutomationID of the current control.
/// </param>
/// <param name="eventID">
/// The event recorded on that control.
/// </param>
///--------------------------------------------------------------------
private void WriteToScript(string automationID, string eventID)
{
// Script code would be generated and written to an output file
// as plain text at this point, but for the
// purposes of this example we just write to the console.
Console.WriteLine(automationID + " - " + eventID);
}
'''--------------------------------------------------------------------
''' <summary>
''' Function to playback through a series of recorded events calling
''' a WriteToScript function for each event of interest.
''' </summary>
''' <remarks>
''' A major drawback to using AutomationID for recording user
''' interactions in a volatile UI is the probability of catastrophic
''' change in the UI. For example, the 'Processes' dialog where items
''' in the listbox container can change with no input from the user.
''' This mandates thtat a record and playback application must be
''' reliant on the tester owning the UI being tested. In other words,
''' there has to be a contract between the provider and client that
''' excludes uncontrolled, external applications. The added benefit
''' is the guarantee that each control in the UI should have an
''' AutomationID assigned to it.
'''
''' This function relies on a UI Automation worker class to create
''' the System.Collections.Generic.Queue object that stores the
''' information for the recorded user interactions. This
''' allows post-processing of the recorded items prior to actually
''' writing them to a script. If this is not necessary the interaction
''' could be written to the script immediately.
''' </remarks>
'''--------------------------------------------------------------------
Private Sub Playback(ByVal targetApp As AutomationElement)
Private Sub Playback(ByVal targetApp As AutomationElement)
'''--------------------------------------------------------------------
''' <summary>
''' Generates script code and outputs the code to a text control in
''' the client.
''' </summary>
''' <param name="automationID">
''' The AutomationID of the current control.
''' </param>
''' <param name="eventID">
''' The event recorded on that control.
''' </param>
'''--------------------------------------------------------------------
Private Sub WriteToScript( _
ByVal automationID As String, ByVal eventID As String)
See Also
AutomationIdProperty
UI Automation Tree Overview
Find a UI Automation Element Based on a Property Condition
UI Automation Control Patterns
4/14/2017 1 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This section provides detailed information about how to use Microsoft UI Automation control patterns.
In This Section
Implementing the UI Automation Dock Control Pattern
Implementing the UI Automation ExpandCollapse Control Pattern
Implementing the UI Automation Grid Control Pattern
Implementing the UI Automation GridItem Control Pattern
Implementing the UI Automation Invoke Control Pattern
Implementing the UI Automation MultipleView Control Pattern
Implementing the UI Automation RangeValue Control Pattern
Implementing the UI Automation Scroll Control Pattern
Implementing the UI Automation ScrollItem Control Pattern
Implementing the UI Automation Selection Control Pattern
Implementing the UI Automation SelectionItem Control Pattern
Implementing the UI Automation Table Control Pattern
Implementing the UI Automation TableItem Control Pattern
Implementing the UI Automation Toggle Control Pattern
Implementing the UI Automation Transform Control Pattern
Implementing the UI Automation Value Control Pattern
Implementing the UI Automation Window Control Pattern
How-to Topics
Implementing the UI Automation Dock Control
Pattern
5/31/2017 2 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic introduces guidelines and conventions for implementing IDockProvider, including information about
properties. Links to additional references are listed at the end of the topic.
The DockPattern control pattern is used to expose the dock properties of a control within a docking container. A
docking container is a control that allows you to arrange child elements horizontally and vertically, relative to each
other. For examples of controls that implement this control pattern, see Control Pattern Mapping for UI Automation
Clients.
Docking Example from Visual Studio Where "Class View" Window Is DockPosition.Right and "Error List" Window Is
DockPosition.Bottom
Exceptions
Providers must throw the following exceptions.
InvalidOperationException SetDockPosition
See Also
UI Automation Control Patterns Overview
Support Control Patterns in a UI Automation Provider
UI Automation Control Patterns for Clients
UI Automation Tree Overview
Use Caching in UI Automation
Implementing the UI Automation ExpandCollapse
Control Pattern
5/31/2017 2 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic introduces guidelines and conventions for implementing IExpandCollapseProvider, including information
about properties, methods, and events. Links to additional references are listed at the end of the overview.
The ExpandCollapsePattern control pattern is used to support controls that visually expand to display more content
and collapse to hide content. For examples of controls that implement this control pattern, see Control Pattern
Mapping for UI Automation Clients.
NOTE
An exception is the menu control, which is an aggregate of individual MenuItem objects. The MenuItem objects can
support the ExpandCollapsePattern control pattern, but the parent Menu control cannot. A similar exception applies
to the Tree and Tree Item controls.
Exceptions
Providers must throw the following exceptions.
See Also
UI Automation Control Patterns Overview
Support Control Patterns in a UI Automation Provider
UI Automation Control Patterns for Clients
Navigate Among UI Automation Elements with TreeWalker
UI Automation Tree Overview
Use Caching in UI Automation
Implementing the UI Automation Grid Control
Pattern
4/14/2017 2 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic introduces guidelines and conventions for implementing IGridProvider, including information about
properties, methods, and events. Links to additional references are listed at the end of the overview.
The GridPattern control pattern is used to support controls that act as containers for a collection of child elements.
The children of this element must implement IGridItemProvider and be organized in a two-dimensional logical
coordinate system that can be traversed by row and column. For examples of controls that implement this control
pattern, see Control Pattern Mapping for UI Automation Clients.
Exceptions
Providers must throw the following exceptions.
ArgumentOutOfRangeException GetItem
ArgumentOutOfRangeException GetItem
See Also
UI Automation Control Patterns Overview
Support Control Patterns in a UI Automation Provider
UI Automation Control Patterns for Clients
Implementing the UI Automation GridItem Control Pattern
UI Automation Tree Overview
Use Caching in UI Automation
Implementing the UI Automation GridItem Control
Pattern
4/14/2017 1 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic introduces guidelines and conventions for implementing IGridItemProvider, including information about
properties. Links to additional references are listed at the end of the overview.
The GridItemPattern control pattern is used to support individual child controls of containers that implement
IGridProvider. For examples of controls that implement this control pattern, see Control Pattern Mapping for UI
Automation Clients.
Exceptions
This control pattern has no associated exceptions.
See Also
UI Automation Control Patterns Overview
Support Control Patterns in a UI Automation Provider
UI Automation Control Patterns for Clients
Implementing the UI Automation Grid Control Pattern
UI Automation Tree Overview
Use Caching in UI Automation
Implementing the UI Automation Invoke Control
Pattern
4/14/2017 3 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic introduces guidelines and conventions for implementing IInvokeProvider, including information about
events and properties. Links to additional references are listed at the end of the topic.
The InvokePattern control pattern is used to support controls that do not maintain state when activated but rather
initiate or perform a single, unambiguous action. Controls that do maintain state, such as check boxes and radio
buttons, must instead implement IToggleProvider and ISelectionItemProvider respectively. For examples of
controls that implement the Invoke control pattern, see Control Pattern Mapping for UI Automation Clients.
Invoking a control is different from selecting an item. However, depending on the control, invoking it may
cause the item to become selected as a side-effect. For example, invoking a Microsoft Word document list
item in the My Documents folder both selects the item and opens the document.
An element can disappear from the UI Automation tree immediately upon being invoked. Requesting
information from the element provided by the event callback may fail as a result. Pre-fetching cached
information is the recommended workaround.
Controls can implement multiple control patterns. For example, the Fill Color control on the Microsoft Excel
toolbar implements both the InvokePattern and the ExpandCollapsePattern control patterns.
ExpandCollapsePattern exposes the menu and the InvokePattern fills the active selection with the chosen
color.
Exceptions
Providers must throw the following exceptions.
See Also
UI Automation Control Patterns Overview
Support Control Patterns in a UI Automation Provider
UI Automation Control Patterns for Clients
Invoke a Control Using UI Automation
UI Automation Tree Overview
Use Caching in UI Automation
Implementing the UI Automation MultipleView
Control Pattern
4/14/2017 1 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic introduces guidelines and conventions for implementing IMultipleViewProvider, including information
about events and properties. Links to additional references are listed at the end of the topic.
The MultipleViewPattern control pattern is used to support controls that provide, and are able to switch between,
multiple representations of the same set of information or child controls.
Examples of controls that can present multiple views include the list view (which can show its contents as
thumbnails, tiles, icons, or details), Microsoft Excel charts (pie, line, bar, cell value with a formula), Microsoft Word
documents (normal, Web layout, print layout, reading layout, outline), Microsoft Outlook calendar (year, month,
week, day), and Microsoft Windows Media Player skins. The supported views are determined by the control
developer and are specific to each control.
Exceptions
Provider must throw the following exceptions.
See Also
UI Automation Control Patterns Overview
Support Control Patterns in a UI Automation Provider
UI Automation Control Patterns for Clients
UI Automation Tree Overview
Use Caching in UI Automation
Implementing the UI Automation RangeValue Control
Pattern
4/14/2017 1 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic introduces guidelines and conventions for implementing IRangeValueProvider, including information
about events and properties. Links to additional references are listed at the end of the topic.
The RangeValuePattern control pattern is used to support controls that can be set to a value within a range. For
examples of controls that implement this control pattern, see Control Pattern Mapping for UI Automation Clients.
Example of a Progress Bar Where Value Is of Type Integer and Minimum and Maximum Property Values Are
Normalized to 0 and 100, Respectively
See Also
UI Automation Control Patterns Overview
Support Control Patterns in a UI Automation Provider
UI Automation Control Patterns for Clients
UI Automation Tree Overview
Use Caching in UI Automation
Implementing the UI Automation Scroll Control
Pattern
5/31/2017 2 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic introduces guidelines and conventions for implementing IScrollProvider, including information about
events and properties. Links to additional references are listed at the end of the topic.
The ScrollPattern control pattern is used to support a control that acts as a scrollable container for a collection of
child objects. The control is not required to use scrollbars to support the scrolling functionality, although it
commonly does.
Exceptions
Providers must throw the following exceptions.
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic introduces guidelines and conventions for implementing the IScrollItemProvider, including information
about properties, methods, and events. Links to additional references are listed at the end of the topic.
The ScrollItemPattern control pattern is used to support individual child controls of containers that implement
IScrollProvider. This control pattern acts as a communication channel between a child control and its container to
ensure that the container can change the currently visible content (or region) within its viewport to display the child
control. For examples of controls that implement this control pattern, see Control Pattern Mapping for UI
Automation Clients.
Exceptions
Providers must throw the following exceptions.
- ScrollIntoView
See Also
UI Automation Control Patterns Overview
Support Control Patterns in a UI Automation Provider
UI Automation Control Patterns for Clients
UI Automation Tree Overview
Use Caching in UI Automation
Implementing the UI Automation Selection Control
Pattern
4/14/2017 2 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic introduces guidelines and conventions for implementing ISelectionProvider, including information about
events and properties. Links to additional references are listed at the end of the topic.
The SelectionPattern control pattern is used to support controls that act as containers for a collection of selectable
child items. The children of this element must implement ISelectionItemProvider. For examples of controls that
implement this control pattern, see Control Pattern Mapping for UI Automation Clients.
The IsSelectionRequired and CanSelectMultiple properties can be dynamic. For example, the initial state of a
control might not have any items selected by default, indicating that IsSelectionRequired is false . However, after
an item is selected, the control must always have at least one item selected. Similarly, in rare cases, a control might
allow multiple items to be selected on initialization, but subsequently allow only single selections to be made.
Exceptions
Providers must throw the following exceptions.
See Also
UI Automation Control Patterns Overview
Support Control Patterns in a UI Automation Provider
UI Automation Control Patterns for Clients
Implementing the UI Automation SelectionItem Control Pattern
UI Automation Tree Overview
Use Caching in UI Automation
Implementing the UI Automation SelectionItem
Control Pattern
4/14/2017 1 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic introduces guidelines and conventions for implementing ISelectionItemProvider, including information
about properties, methods, and events. Links to additional references are listed at the end of the overview.
The SelectionItemPattern control pattern is used to support controls that act as individual, selectable child items of
container controls that implement ISelectionProvider. For examples of controls that implement the SelectionItem
control pattern, see Control Pattern Mapping for UI Automation Clients
Exceptions
Providers must throw the following exceptions.
See Also
UI Automation Control Patterns Overview
Support Control Patterns in a UI Automation Provider
UI Automation Control Patterns for Clients
Implementing the UI Automation Selection Control Pattern
UI Automation Tree Overview
Use Caching in UI Automation
Fragment Provider Sample
Implementing the UI Automation Table Control
Pattern
4/14/2017 1 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic introduces guidelines and conventions for implementing ITableProvider, including information about
properties, methods, and events. Links to additional references are listed at the end of the overview.
The TablePattern control pattern is used to support controls that act as containers for a collection of child elements.
The children of this element must implement ITableItemProvider and be organized in a two-dimensional logical
coordinate system that can be traversed by row and column. This control pattern is analogous to IGridProvider,
with the distinction that any control implementing ITableProvider must also expose a column and/or row header
relationship for each child element. For examples of controls that implement this control pattern, see Control
Pattern Mapping for UI Automation Clients.
NOTE
This concept becomes evident in a Microsoft Excel spreadsheet where a user has defined a "First name" column. This column
now has two headersthe "First name" header defined by the user and the alphanumeric designation for that column
assigned by the application.
See Implementing the UI Automation Grid Control Pattern for related grid functionality.
Exceptions
This control pattern has no associated exceptions.
See Also
UI Automation Control Patterns Overview
Support Control Patterns in a UI Automation Provider
UI Automation Control Patterns for Clients
Implementing the UI Automation TableItem Control Pattern
Implementing the UI Automation Grid Control Pattern
UI Automation Tree Overview
Use Caching in UI Automation
Implementing the UI Automation TableItem Control
Pattern
4/14/2017 1 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic introduces guidelines and conventions for implementing ITableItemProvider, including information
about events and properties. Links to additional references are listed at the end of the overview.
The TableItemPattern control pattern is used to support child controls of containers that implement ITableProvider.
Access to individual cell functionality is provided by the required concurrent implementation of IGridItemProvider.
This control pattern is analogous to IGridItemProvider with the distinction that any control implementing
ITableItemProvider must programmatically expose the relationship between the individual cell and its row and
column information. For examples of controls that implement this control pattern, see Control Pattern Mapping for
UI Automation Clients.
Exceptions
This control pattern has no associated exceptions.
See Also
UI Automation Control Patterns Overview
Support Control Patterns in a UI Automation Provider
UI Automation Control Patterns for Clients
Implementing the UI Automation Table Control Pattern
Implementing the UI Automation GridItem Control Pattern
UI Automation Tree Overview
Use Caching in UI Automation
Implementing the UI Automation Toggle Control
Pattern
5/31/2017 1 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic introduces guidelines and conventions for implementing IToggleProvider, including information about
methods and properties. Links to additional references are listed at the end of the topic.
The TogglePattern control pattern is used to support controls that can cycle through a set of states and maintain a
state once set. For examples of controls that implement this control pattern, see Control Pattern Mapping for UI
Automation Clients.
Exceptions
This control pattern has no associated exceptions.
See Also
UI Automation Control Patterns Overview
Support Control Patterns in a UI Automation Provider
UI Automation Control Patterns for Clients
Get the Toggle State of a Check Box Using UI Automation
UI Automation Tree Overview
Use Caching in UI Automation
Implementing the UI Automation Transform Control
Pattern
4/14/2017 1 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic introduces guidelines and conventions for implementing ITransformProvider, including information
about properties, methods, and events. Links to additional references are listed at the end of the topic.
The TransformPattern control pattern is used to support controls that can be moved, resized, or rotated within a
two-dimensional space. For examples of controls that implement this control pattern, see Control Pattern Mapping
for UI Automation Clients.
Exceptions
Providers must throw the following exceptions.
InvalidOperationException Move
InvalidOperationException Resize
InvalidOperationException Rotate
See Also
UI Automation Control Patterns Overview
Support Control Patterns in a UI Automation Provider
UI Automation Control Patterns for Clients
UI Automation Tree Overview
Use Caching in UI Automation
Implementing the UI Automation Value Control
Pattern
4/14/2017 2 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic introduces guidelines and conventions for implementing IValueProvider, including information on events
and properties. Links to additional references are listed at the end of the topic.
The ValuePattern control pattern is used to support controls that have an intrinsic value not spanning a range and
that can be represented as a string. This string can be editable, depending on the control and its settings. For
examples of controls that implement this pattern, see Control Pattern Mapping for UI Automation Clients.
Exceptions
Providers must throw the following exceptions.
InvalidOperationException SetValue
ArgumentException SetValue
ElementNotEnabledException SetValue
See Also
UI Automation Control Patterns Overview
Support Control Patterns in a UI Automation Provider
UI Automation Control Patterns for Clients
TextPattern Insert Text Sample
UI Automation Tree Overview
Use Caching in UI Automation
Implementing the UI Automation Window Control
Pattern
5/31/2017 1 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic introduces guidelines and conventions for implementing IWindowProvider, including information about
WindowPattern properties, methods, and events. Links to additional references are listed at the end of the topic.
The WindowPattern control pattern is used to support controls that provide fundamental window-based
functionality within a traditional graphical user interface (GUI). Examples of controls that must implement this
control pattern include top-level application windows, multiple-document interface (MDI) child windows, resizable
split pane controls, modal dialogs and balloon help windows.
Exceptions
Providers must throw the following exceptions.
InvalidOperationException SetVisualState
ArgumentOutOfRangeException WaitForInputIdle
See Also
UI Automation Control Patterns Overview
Support Control Patterns in a UI Automation Provider
UI Automation Control Patterns for Clients
UI Automation Tree Overview
Use Caching in UI Automation
UI Automation Control Patterns How-to Topics
4/14/2017 1 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
In This Section
Expose the Content of a Table Using UI Automation
Get Supported UI Automation Control Patterns
Get the Toggle State of a Check Box Using UI Automation
Invoke a Control Using UI Automation
Move a UI Automation Element
Expose the Content of a Table Using UI Automation
4/14/2017 8 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes defined
in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows Automation
API: UI Automation.
This topic shows how Microsoft UI Automation can be used to expose the content and intrinsic properties of each
cell within a tabular control.
Example
The following code example demonstrates how to obtain a AutomationElement that represents the content of a
table cell; cell properties such as row and column indices, row and column spans, and row and column header
information are also obtained. This example uses a focus change event handler to simulate keyboard traversal of a
tabular control that implements UI Automation. Information for each table item is exposed on a focus change event.
NOTE
Since focus changes are global desktop events, focus change events outside the table should be filtered. See the TrackFocus
Sample for a related implementation.
/// -------------------------------------------------------------------
/// <summary>
/// Starts the target application and returns the AutomationElement
/// obtained from the targets window handle.
/// </summary>
/// <param name="exe">
/// The target application.
/// </param>
/// <param name="filename">
/// The text file to be opened in the target application
/// </param>
/// <returns>
/// An AutomationElement representing the target application.
/// </returns>
/// -------------------------------------------------------------------
private AutomationElement StartTarget(string exe, string filename)
{
// Start text editor and load with a text file.
Process p = Process.Start(exe, filename);
return targetApp;
}
''' -------------------------------------------------------------------
''' <summary>
''' Starts the target application and returns the AutomationElement
''' obtained from the targets window handle.
''' </summary>
''' <param name="exe">
''' The target application.
''' </param>
''' <param name="filename">
''' The text file to be opened in the target application
''' </param>
''' <returns>
''' An AutomationElement representing the target application.
''' </returns>
''' -------------------------------------------------------------------
Private Function StartTarget(ByVal exe As String, ByVal filename As String) As AutomationElement
' Start text editor and load with a text file.
Dim p As Process = Process.Start(exe, filename)
Return targetApp
End Function
/// -------------------------------------------------------------------
/// <summary>
/// Obtain the table control of interest from the target application.
/// </summary>
/// <param name="targetApp">
/// The target application.
/// </param>
/// <returns>
/// An AutomationElement representing a table control.
/// </returns>
/// -------------------------------------------------------------------
private AutomationElement GetTableElement(AutomationElement targetApp)
{
// The control type we're looking for; in this case 'Document'
PropertyCondition cond1 =
new PropertyCondition(
AutomationElement.ControlTypeProperty,
ControlType.Table);
AutomationElement targetTableElement =
targetApp.FindFirst(TreeScope.Descendants, tableCondition);
try
{
tableItemPattern =
targetControl.GetCurrentPattern(
TableItemPattern.Pattern)
as TableItemPattern;
}
// Object doesn't support the
// TableItemPattern control pattern
catch (InvalidOperationException)
{
return null;
}
return tableItemPattern;
}
'''--------------------------------------------------------------------
''' <summary>
''' Obtains a TableItemPattern control pattern from an
''' AutomationElement.
''' </summary>
''' <param name="targetControl">
''' The AutomationElement of interest.
''' </param>
''' <returns>
''' A TableItemPattern object.
''' </returns>
'''--------------------------------------------------------------------
Private Function GetTableItemPattern( _
ByVal targetControl As AutomationElement) As TableItemPattern
Dim tableItemPattern As TableItemPattern = Nothing
Try
tableItemPattern = DirectCast( _
targetControl.GetCurrentPattern(tableItemPattern.Pattern), TableItemPattern)
Catch exc As InvalidOperationException
' Object doesn't support the
' GridPattern control pattern
Return Nothing
End Try
Return tableItemPattern
try
{
tablePattern =
targetControl.GetCurrentPattern(
TablePattern.Pattern)
as TablePattern;
}
// Object doesn't support the
// TablePattern control pattern
catch (InvalidOperationException)
{
return null;
}
return tablePattern;
}
'''--------------------------------------------------------------------
''' <summary>
''' Obtains a TablePattern control pattern from an
''' AutomationElement.
''' </summary>
''' <param name="targetControl">
''' The AutomationElement of interest.
''' </param>
''' <returns>
''' A TablePattern object.
''' </returns>
'''--------------------------------------------------------------------
Private Function GetTablePattern( _
ByVal targetControl As AutomationElement) As TablePattern
Dim tablePattern As TablePattern = Nothing
Try
tablePattern = DirectCast( _
targetControl.GetCurrentPattern(tablePattern.Pattern), _
TablePattern)
Catch exc As InvalidOperationException
' Object doesn't support the
' TablePattern control pattern
Return Nothing
End Try
Return tablePattern
'''--------------------------------------------------------------------
''' <summary>
''' Set up table item event listeners.
''' </summary>
''' <remarks>
''' The event listener is essentially a focus change listener.
''' Since this is a global desktop listener, a filter would be required
''' to ignore focus change events outside the table.
''' </remarks>
'''--------------------------------------------------------------------
Private Sub SetTableItemEventListeners( _
ByVal targetControl As AutomationElement)
Dim tableItemFocusChangedListener As AutomationFocusChangedEventHandler = _
AddressOf OnTableItemFocusChange
Automation.AddAutomationFocusChangedEventHandler( _
tableItemFocusChangedListener)
///--------------------------------------------------------------------
/// <summary>
/// Event handler for table item focus change.
/// Can be used to track traversal of individual table items
/// within a table.
/// </summary>
/// <param name="src">Object that raised the event.</param>
/// <param name="e">Event arguments.</param>
///--------------------------------------------------------------------
private void OnTableItemFocusChange(
object src, AutomationFocusChangedEventArgs e)
{
// Make sure the element still exists. Elements such as tooltips
// can disappear before the event is processed.
AutomationElement sourceElement;
try
{
sourceElement = src as AutomationElement;
}
catch (ElementNotAvailableException)
{
return;
}
if (tablePattern == null)
{
return;
}
///--------------------------------------------------------------------
/// <summary>
/// Handles the application shutdown.
/// </summary>
/// <param name="args">Event arguments.</param>
///--------------------------------------------------------------------
protected override void OnExit(System.Windows.ExitEventArgs args)
{
Automation.RemoveAllEventHandlers();
base.OnExit(args);
}
'''--------------------------------------------------------------------
''' <summary>
''' Event handler for table item focus change.
''' Can be used to track traversal of individual table items
''' within a table.
''' </summary>
''' <param name="src">Object that raised the event.</param>
''' <param name="e">Event arguments.</param>
'''--------------------------------------------------------------------
Private Sub OnTableItemFocusChange( _
Private Sub OnTableItemFocusChange( _
ByVal src As Object, ByVal e As AutomationFocusChangedEventArgs)
' Make sure the element still exists. Elements such as tooltips
' can disappear before the event is processed.
Dim sourceElement As AutomationElement
Try
sourceElement = DirectCast(src, AutomationElement)
Catch exc As ElementNotAvailableException
Return
End Try
'''--------------------------------------------------------------------
''' <summary>
''' Handles the application shutdown.
''' </summary>
''' <param name="args">Event arguments.</param>
'''--------------------------------------------------------------------
Protected Overrides Sub OnExit(ByVal args As System.Windows.ExitEventArgs)
Automation.RemoveAllEventHandlers()
MyBase.OnExit(args)
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes defined
in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows Automation
API: UI Automation.
This topic shows how to retrieve control pattern objects from UI Automation elements.
Obtain All Control Patterns
1. Get the AutomationElement whose control patterns you are interested in.
2. Call GetSupportedPatterns to get all control patterns from the element.
Cau t i on
It is strongly recommended that a client not use GetSupportedPatterns. Performance can be severely affected as
this method calls GetCurrentPattern internally for each existing control pattern. If possible, a client should call
GetCurrentPattern for the key patterns of interest.
Obtain a Specific Control Pattern
1. Get the AutomationElement whose control patterns you are interested in.
2. Call GetCurrentPattern or TryGetCurrentPattern to query for a specific pattern. These methods are similar,
but if the pattern is not found, GetCurrentPattern raises an exception, and TryGetCurrentPattern returns
false .
Example
The following example retrieves an AutomationElement for a list item and obtains a SelectionItemPattern from that
element.
/// <summary>
/// Sets the focus to a list and selects a string item in that list.
/// </summary>
/// <param name="listElement">The list element.</param>
/// <param name="itemText">The text to select.</param>
/// <remarks>
/// This deselects any currently selected items. To add the item to the current selection
/// in a multiselect list, use AddToSelection instead of Select.
/// </remarks>
public void SelectListItem(AutomationElement listElement, String itemText)
{
if ((listElement == null) || (itemText == ""))
{
throw new ArgumentException("Argument cannot be null or empty.");
}
listElement.SetFocus();
Condition cond = new PropertyCondition(
AutomationElement.NameProperty, itemText, PropertyConditionFlags.IgnoreCase);
AutomationElement elementItem = listElement.FindFirst(TreeScope.Children, cond);
if (elementItem != null)
{
SelectionItemPattern pattern;
try
{
pattern = elementItem.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;
}
catch (InvalidOperationException ex)
{
Console.WriteLine(ex.Message); // Most likely "Pattern not supported."
return;
}
pattern.Select();
}
}
''' <summary>
''' Sets the focus to a list and selects a string item in that list.
''' </summary>
''' <param name="listElement">The list element.</param>
''' <param name="itemText">The text to select.</param>
''' <remarks>
''' This deselects any currently selected items. To add the item to the current selection
''' in a multiselect list, use AddToSelection instead of Select.
''' </remarks>
Public Sub SelectListItem(ByVal listElement As AutomationElement, ByVal itemText As String)
If listElement Is Nothing OrElse itemText = "" Then
Throw New ArgumentException("Argument cannot be null or empty.")
End If
listElement.SetFocus()
Dim cond As New PropertyCondition(AutomationElement.NameProperty, itemText,
PropertyConditionFlags.IgnoreCase)
Dim elementItem As AutomationElement = listElement.FindFirst(TreeScope.Children, cond)
If Not (elementItem Is Nothing) Then
Dim pattern As SelectionItemPattern
Try
pattern = DirectCast(elementItem.GetCurrentPattern(SelectionItemPattern.Pattern), _
SelectionItemPattern)
Catch ex As InvalidOperationException
Console.WriteLine(ex.Message) ' Most likely "Pattern not supported."
Return
End Try
pattern.Select()
End If
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic shows how to use Microsoft UI Automation to get the toggle state of a control.
Example
This example uses the GetCurrentPattern method of the AutomationElement class to obtain a TogglePattern object
from a control and return its ToggleState property.
/// <summary>
/// Gets the toggle state of an element in the target application.
/// </summary>
/// <param name="element">The target element.</param>
private bool IsElementToggledOn(AutomationElement element)
{
if (element == null)
{
// TODO: Invalid parameter error handling.
return false;
}
Object objPattern;
TogglePattern togPattern;
if (true == element.TryGetCurrentPattern(TogglePattern.Pattern, out objPattern))
{
togPattern = objPattern as TogglePattern;
return togPattern.Current.ToggleState == ToggleState.On;
}
// TODO: Object doesn't support TogglePattern error handling.
return false;
}
''' <summary>
''' Gets the toggle state of an element in the target application.
''' </summary>
''' <param name="element">The target element.</param>
Private Function IsElementToggledOn(ByVal element As AutomationElement) As Boolean
If element Is Nothing Then
' TODO: Invalid parameter error handling.
Return False
End If
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
Example
This example uses the TryGetCurrentPattern method of the AutomationElement class to generate an InvokePattern
object and invoke a control by using the Invoke method.
///--------------------------------------------------------------------
/// <summary>
/// Walks the UI Automation tree of the target and reports the control
/// type of each element it finds in the control view to the client.
/// </summary>
/// <param name="targetTreeViewElement">
/// The root of the search on this iteration.
/// </param>
/// <param name="elementIndex">
/// The TreeView index for this iteration.
/// </param>
/// <remarks>
/// This is a recursive function that maps out the structure of the
/// subtree of the target beginning at the AutomationElement passed in
/// as the rootElement on the first call. This could be, for example,
/// an application window.
/// CAUTION: Do not pass in AutomationElement.RootElement. Attempting
/// to map out the entire subtree of the desktop could take a very
/// long time and even lead to a stack overflow.
/// </remarks>
///--------------------------------------------------------------------
private void FindTreeViewDescendants(
AutomationElement targetTreeViewElement, int treeviewIndex)
{
if (targetTreeViewElement == null)
return;
AutomationElement elementNode =
TreeWalker.ControlViewWalker.GetFirstChild(targetTreeViewElement);
elementInfoCompile.Append(controlName)
.Append(" (")
.Append(elementNode.Current.ControlType.LocalizedControlType)
.Append(" - ")
.Append(autoIdName)
.Append(")");
'''--------------------------------------------------------------------
''' <summary>
''' Walks the UI Automation tree of the target and reports the control
''' type of each element it finds in the control view to the client.
''' </summary>
''' <param name="targetTreeViewElement">
''' The root of the search on this iteration.
''' </param>
''' <param name="treeviewIndex">
''' The TreeView index for this iteration.
''' </param>
''' <remarks>
''' This is a recursive function that maps out the structure of the
''' subtree beginning at the AutomationElement passed in as
''' rootElement on the first call. This could be, for example,
''' an application window.
''' CAUTION: Do not pass in AutomationElement.RootElement. Attempting
''' to map out the entire subtree of the desktop could take a very
''' long time and even lead to a stack overflow.
''' </remarks>
'''--------------------------------------------------------------------
Private Sub FindTreeViewDescendants( _
ByVal targetTreeViewElement As AutomationElement, _
ByVal treeviewIndex As Integer)
If (IsNothing(targetTreeViewElement)) Then
Return
End If
elementInfoCompile.Append(controlName).Append(" (") _
.Append(elementNode.Current.ControlType.LocalizedControlType) _
.Append(" - ").Append(autoIdName).Append(")")
' Test for the control patterns of interest for this sample.
' Test for the control patterns of interest for this sample.
Dim objPattern As Object = Nothing
Dim expcolPattern As ExpandCollapsePattern
If True = elementNode.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, objPattern) Then
expcolPattern = DirectCast(objPattern, ExpandCollapsePattern)
If expcolPattern.Current.ExpandCollapseState <> ExpandCollapseState.LeafNode Then
Dim expcolButton As New Button()
expcolButton.Margin = New Thickness(0, 0, 0, 5)
expcolButton.Height = 20
expcolButton.Width = 100
expcolButton.Content = "ExpandCollapse"
expcolButton.Tag = expcolPattern
AddHandler expcolButton.Click, AddressOf ExpandCollapse_Click
clientTreeViews(treeviewIndex).Children.Add(expcolButton)
End If
End If
Dim togPattern As TogglePattern
If True = elementNode.TryGetCurrentPattern(TogglePattern.Pattern, objPattern) Then
togPattern = DirectCast(objPattern, TogglePattern)
Dim togButton As New Button()
togButton.Margin = New Thickness(0, 0, 0, 5)
togButton.Height = 20
togButton.Width = 100
togButton.Content = "Toggle"
togButton.Tag = togPattern
AddHandler togButton.Click, AddressOf Toggle_Click
clientTreeViews(treeviewIndex).Children.Add(togButton)
End If
Dim invPattern As InvokePattern
If True = elementNode.TryGetCurrentPattern(InvokePattern.Pattern, objPattern) Then
invPattern = DirectCast(objPattern, InvokePattern)
Dim invButton As New Button()
invButton.Margin = New Thickness(0)
invButton.Height = 20
invButton.Width = 100
invButton.Content = "Invoke"
invButton.Tag = invPattern
AddHandler invButton.Click, AddressOf Invoke_Click
clientTreeViews(treeviewIndex).Children.Add(invButton)
End If
' Display compiled information about the control.
elementInfo.Content = elementInfoCompile
Dim sep As New Separator()
clientTreeViews(treeviewIndex).Children.Add(sep)
'''--------------------------------------------------------------------
''' <summary>
''' Handles the Invoke click event on the client control.
''' The client click handler calls Invoke() on the equivalent target control.
''' </summary>
''' <param name="sender">The object that raised the event.</param>
''' <param name="e">Event arguments.</param>
''' <remarks>
''' The Tag property of the FrameworkElement, the client button in this
''' case, is used to store the InvokePattern object previously obtained
''' from the associated target control.
''' </remarks>
'''--------------------------------------------------------------------
Private Sub Invoke_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim clientButton As Button = DirectCast(sender, Button)
Dim targetInvokePattern As InvokePattern = _
DirectCast(clientButton.Tag, InvokePattern)
If (IsNothing(targetInvokePattern)) Then
Return
End If
targetInvokePattern.Invoke()
statusText.Text = "Button invoked."
End Sub 'Invoke_Click
See Also
InvokePattern and ExpandCollapsePattern Menu Item Sample
Move a UI Automation Element
4/14/2017 4 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes defined
in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows Automation
API: UI Automation.
This example demonstrates how to move a UI Automation element to a specified screen location.
Example
The following example uses the WindowPattern and TransformPattern control patterns to programmatically move
a Win32 target application to discrete screen locations and track the BoundingRectangleProperty
AutomationPropertyChangedEvent.
/// <summary>
/// The Startup handler.
/// </summary>
/// <param name="e">The event arguments</param>
protected override void OnStartup(StartupEventArgs e)
{
// Start the WindowMove client.
CreateWindow();
try
{
// Obtain an AutomationElement from the target window handle.
targetWindow = StartTargetApp(targetApplication);
// Move element
transformPattern.Move(0, 0);
}
else
{
Feedback("Wndow is not moveable.");
}
}
catch (ElementNotAvailableException)
{
Feedback("Client window no longer available.");
return;
}
catch (InvalidOperationException)
{
Feedback("Client window cannot be moved.");
return;
}
catch (Exception exc)
{
Feedback(exc.ToString());
}
}
'' <summary>
'' The Startup handler.
'' </summary>
'' <param name="e">The event arguments</param>
Protected Overrides Sub OnStartup(ByVal e As StartupEventArgs)
Try
' Obtain an AutomationElement from the target window handle.
targetWindow = StartTargetApp(targetApplication)
End Try
if (windowPattern.Current.WindowVisualState ==
WindowVisualState.Minimized)
windowPattern.SetWindowVisualState(WindowVisualState.Normal);
double X = double.Parse(xCoordinate.Text);
double Y = double.Parse(yCoordinate.Text);
if ((Y < 0) ||
(Y >= (SystemParameters.WorkArea.Height -
targetWindow.Current.BoundingRectangle.Height)))
{
Feedback("Y-coordinate would place the window all or partially off-screen.");
yCoordinate.Background = System.Windows.Media.Brushes.Yellow;
}
End Try
End Sub
See Also
WindowPattern Sample
UI Automation Text Pattern
4/14/2017 1 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic contains overviews and how-to topics to help you get started in programming for text elements in
Microsoft UI Automation.
In This Section
UI Automation TextPattern Overview
TextPattern and Embedded Objects Overview
How-to Topics
Reference
System.Windows.Automation.Text
See Also
UI Automation Control Patterns
UI Automation Control Patterns for Clients
UI Automation TextPattern Overview
5/31/2017 7 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This overview describes how to use Microsoft UI Automation to expose the textual content, including format and
style attributes, of text controls in UI Automation-supported platforms. These controls include, but are not limited
to, the Microsoft .NET Framework TextBox and RichTextBox as well as their Win32 equivalents.
Exposing the textual content of a control is accomplished through the use of the TextPattern control pattern, which
represents the contents of a text container as a text stream. In turn, TextPattern requires the support of the
TextPatternRange class to expose format and style attributes. TextPatternRange supports TextPattern by
representing contiguous or multiple, disjoint text spans in a text container with a collection of Start and End
endpoints. TextPatternRange supports functionality such as selection, comparison, retrieval and traversal.
NOTE
The TextPattern classes do not provide a means to insert or modify text. However, depending on the control, this may be
accomplished by the UI Automation ValuePattern or through direct keyboard input. See the TextPattern Insert Text Sample
for an example.
The functionality described in this overview is vital to assistive technology vendors and their end users. Assistive
technologies can use UI Automation to gather complete text formatting information for the user and provide
programmatic navigation and selection of text by TextUnit (character, word, line, or paragraph).
Control Types
Text
The Text control is the basic element representing a piece of text on the screen.
A standalone text control can be used as a label or static text on a form. Text controls can also be contained within
the structure of a ListItem, TreeItem or DataItem.
NOTE
Text controls might not appear in the content view of the UI Automation tree (see UI Automation Tree Overview). This is
because text controls are often displayed through the Name property of another control. For instance, the text that is used
to label an Edit control is exposed through the Name property of the Edit control. Because the Edit control is in the content
view of the UI Automation tree, it is not necessary for the text element itself to be in that view of the UI Automation tree.
The only text that shows up in the content view is text that is not redundant information. This enables any assistive
technology to quickly filter only on the pieces of information that their users need.
Edit
Edit controls enable a user to view and edit a single line of text.
NOTE
The single line of text may wrap in certain layout scenarios.
Document
Document controls let a user navigate and obtain information from multiple pages of text.
System.Windows.Automation.TextPattern Class The entry point for the Microsoft UI Automation text model.
NOTE
The provider may skip support for a specific TextUnit by deferring to the next largest TextUnit supported in the following
order: Character, Format, Word, Line, Paragraph, Page, and Document.
System.Windows.Automation.TextPatternIdentifiers Contains values that are used as identifiers for text providers
Class (see TextPatternIdentifiers).
Security
The UI Automation architecture was designed with security in mind (see UI Automation Security Overview).
However, the TextPattern classes described in this overview require some specific security considerations.
Microsoft UI Automation text providers supply read-only interfaces and do not provide the ability to change
the existing text in a control.
UI Automation clients can only use Microsoft UI Automation if they are fully "trusted". An example of this
would be the protected Logon Desktop, where only known and trusted applications can run.
Developers of UI Automation providers should be aware that all information they choose to expose in their
controls through Microsoft UI Automation is essentially public and fully accessible by other code. Microsoft
UI Automation makes no effort to determine the trustworthiness of any UI Automation client and therefore
the UI Automation provider should not expose protected content or sensitive textual information (such as
password fields).
One of the most significant changes in security for Windows Vista is broadly referred to as "Secure Input"
which encompasses technologies such as Least-privileged (or Limited) User Accounts (LUA) and UI Privilege
Level Isolation (UIPI).
UIPI prevents one program from controlling and/or monitoring another more "privileged" program,
preventing cross-process window message attacks that spoof user input.
LUA sets limits on the privileges of applications being run by users in the Administrators group.
Applications won't necessarily have administrator privileges, but will instead run with the least
privileges necessary. As a consequence, there may be some restrictions enforced in LUA scenarios.
Most notably string truncation (including TextPattern strings), where it may be necessary to limit the
size of strings being retrieved from administrator-level applications so they aren't forced to allocate
memory to the point of disabling the application.
Performance
Because TextPattern relies on cross-process calls for most of its functionality, it does not provide a caching
mechanism to improve performance when processing content. This is unlike other control patterns in Microsoft UI
Automation that can be accessed using the GetCachedPattern or TryGetCachedPattern methods.
One tactic for improving performance is by making sure UI Automation clients attempt to retrieve moderately-
sized blocks of text using GetText. For example, GetText(1) calls will incur cross-process hits for each character
whereas one GetText(-1) call will incur one cross-process hit, but can have high latency depending on the size of
the text provider.
TextPattern Terminology
Attribute
A formatting characteristic of a text range (for example, IsItalicAttribute or FontNameAttribute).
Degenerate Range
A degenerate range is an empty or zero-character text range. For the purposes of the TextPattern control pattern,
the text insertion point (or system caret) is considered a degenerate range. If no text is selected, GetSelection
would return a degenerate range at the text insertion point and RangeFromPoint would return a degenerate range
as its starting endpoint. RangeFromChild and GetVisibleRanges may return degenerate ranges when the text
provider cannot find any text ranges that match the given condition. This degenerate range can be used as a
starting endpoint within the text provider. FindText and FindAttribute return a null reference ( Nothing in Microsoft
Visual Basic .NET) to avoid confusion with a discovered range versus a degenerate range.
Embedded Object
There are two types of embedded objects in the UI Automation text model. They consist of text-based content
elements such as hyperlinks or tables, and control elements such as images and buttons. For more detailed
information, see Access Embedded Objects Using UI Automation.
Endpoint
The absolute Start or End point of a text range within a text container.
See Also
UI Automation Control Patterns for Clients
UI Automation Control Patterns Overview
UI Automation Tree Overview
Use Caching in UI Automation
Support Control Patterns in a UI Automation Provider
Control Pattern Mapping for UI Automation Clients
Text Services Framework
TextPattern and Embedded Objects Overview
5/31/2017 5 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This overview describes how Microsoft UI Automation exposes embedded objects, or child elements, within a text
document or container.
In UI Automation an embedded object is any element that has non-textual boundaries; for example, an image,
hyperlink, table, or document type such as an Microsoft Excel spreadsheet or Microsoft Windows Media file. This
differs from the standard definition, where an element is created in one application and embedded, or linked,
within another. Whether the object can be edited within its original application is irrelevant in the context of UI
Automation.
Example of a Text Container with Table, Image, and Hyperlink Embedded Objects
Example of the Content View for a Portion of the Preceding Text Container
Example of a text stream with embedded objects and their range spans
When it is necessary to traverse the content of a text range, a series of steps are involved behind the scenes in
order for the Move method to execute successfully.
1. The text range is normalized; that is, the text range is collapsed to a degenerate range at the Start endpoint,
which makes the End endpoint superfluous. This step is necessary to remove ambiguity in situations where
a text range spans TextUnit boundaries: for example, "{The U}RL http://www.microsoft.com is embedded in
text" where "{" and "}" are the text range endpoints.
2. The resulting range is moved backward in the DocumentRange to the beginning of the requested TextUnit
boundary.
3. The range is moved forward or backward in the DocumentRange by the requested number of TextUnit
boundaries.
4. The range is then expanded from a degenerate range state by moving the End endpoint by one requested
TextUnit boundary.
Common Scenarios
The following sections present examples of the most common scenarios that involve embedded objects.
Legend for the examples shown:
{ = Start
} = End
Hyperlink
Example 1 - A text range that contains an embedded text hyperlink
{The URL http://www.microsoft.com is embedded in text}.
RangeFromChild where AutomationElement is the object Returns the range that represents "http://www.microsoft.com".
returned by the previous GetChildren method.
GetChildren Returns null since the text range doesn't span the entire
URL string.
Example 3 - A text range that partially spans the content of a text container. The text container has an
embedded text hyperlink that is not part of the text range.
{The URL} http://www.microsoft.com is embedded in text.
Move with parameters of (TextUnit.Word, 1). Moves the text range span to "http" since the text of the
hyperlink is comprised of individual words. In this case, the
hyperlink is not treated as a single object.
Image
Example 1 - A text range that contains an embedded image
{The image is embedded in text}.
GetText Returns the string "The is embedded in text". Any ALT text
associated with the image cannot be expected to be included
in the text stream.
RangeFromChild where AutomationElement is the object Returns the degenerate range that represents " ".
returned by the previous GetChildren method.
Example 2 - A text range that partially spans the content of a text container. The text container has an
embedded image that is not part of the text range.
Move with parameters of (TextUnit.Word, 1). Moves the text range span to "is ". Because only text-based
embedded objects are considered part of the text stream, the
image in this example does not affect Move or its return value
(1 in this case).
Table
Table used for examples
CELL WITH IMAGE CELL WITH TEXT
Image for Z
GetItem with parameters (0,0) Returns the AutomationElement representing the content of
the table cell; in this case, the element is a text control.
RangeFromChild where AutomationElement is the object Returns the range that spans the image .
returned by the previous GetItem method.
GetEnclosingElement for the object returned by the previous Returns the AutomationElement representing the table cell; in
RangeFromChild method. this case, the element is a text control that supports
TableItemPattern.
GetEnclosingElement for the object returned by the previous Returns the AutomationElement representing the table.
GetEnclosingElement method.
GetEnclosingElement for the object returned by the previous Returns the AutomationElement that represents the text
GetEnclosingElement method. provider itself.
GetItem with parameters of (1,1). Returns the AutomationElement representing the content of
the table cell; in this case, the element is a text control.
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This section includes topics that explain how to use UI Automation text pattern.
In This Section
Add Content to a Text Box Using UI Automation
Find and Highlight Text Using UI Automation
Obtain Text Attributes Using UI Automation
Obtain Mixed Text Attribute Details Using UI Automation
Traverse Text Using UI Automation
Access Embedded Objects Using UI Automation
Add Content to a Text Box Using UI Automation
4/14/2017 5 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic contains example code that demonstrates how to use Microsoft UI Automation to insert text into a
single-line text box. An alternate method is provided for multi-line and rich text controls where UI Automation is
not applicable. For comparison purposes, the example also demonstrates how to use Win32 methods to
accomplish the same results.
Example
The following example steps through a sequence of text controls in a target application. Each text control is tested
to see if a ValuePattern object can be obtained from it using the TryGetCurrentPattern method. If the text control
does support ValuePattern, the SetValue method is used to insert a user-defined string into the text control.
Otherwise, the System.Windows.Forms.SendKeys.SendWait method is used.
///--------------------------------------------------------------------
/// <summary>
/// Sets the values of the text controls using managed methods.
/// </summary>
/// <param name="s">The string to be inserted.</param>
///--------------------------------------------------------------------
private void SetValueWithUIAutomation(string s)
{
foreach (AutomationElement control in textControls)
{
InsertTextUsingUIAutomation(control, s);
}
}
///--------------------------------------------------------------------
/// <summary>
/// Inserts a string into each text control of interest.
/// </summary>
/// <param name="element">A text control.</param>
/// <param name="value">The string to be inserted.</param>
///--------------------------------------------------------------------
private void InsertTextUsingUIAutomation(AutomationElement element,
string value)
{
try
{
// Validate arguments / initial setup
if (value == null)
throw new ArgumentNullException(
"String parameter must not be null.");
if (element == null)
throw new ArgumentNullException(
"AutomationElement parameter must not be null");
((ValuePattern)valuePattern).SetValue(value);
}
}
catch (ArgumentNullException exc)
{
feedbackText.Append(exc.Message);
}
catch (InvalidOperationException exc)
{
feedbackText.Append(exc.Message);
}
finally
{
Feedback(feedbackText.ToString());
}
}
'' --------------------------------------------------------------------
'' <summary>
'' Sets the values of the text controls using managed methods.
'' </summary>
'' <param name="s">The string to be inserted.</param>
'' --------------------------------------------------------------------
Private Sub SetValueWithUIAutomation(ByVal s As String)
Dim control As AutomationElement
For Each control In textControls
InsertTextWithUIAutomation(control, s)
Next control
End Sub
'' --------------------------------------------------------------------
'' <summary>
'' Inserts a string into each text control of interest.
'' </summary>
'' <param name="element">A text control.</param>
'' <param name="value">The string to be inserted.</param>
'' --------------------------------------------------------------------
Private Sub InsertTextWithUIAutomation( _
ByVal element As AutomationElement, ByVal value As String)
Try
' Validate arguments / initial setup
If value Is Nothing Then
Throw New ArgumentNullException( _
"String parameter must not be null.")
End If
' Delete existing content in the control and insert new content.
SendKeys.SendWait("^{HOME}") ' Move to start of control
SendKeys.SendWait("^+{END}") ' Select everything
SendKeys.SendWait("{DEL}") ' Delete selection
SendKeys.SendWait(value)
Else
' Control supports the ValuePattern pattern so we can
' use the SetValue method to insert content.
feedbackText.Append("The control with an AutomationID of ") _
.Append(element.Current.AutomationId.ToString()) _
.Append(" supports ValuePattern.") _
.AppendLine(" Using ValuePattern.SetValue().").AppendLine()
End Sub
See Also
TextPattern Insert Text Sample
Find and Highlight Text Using UI Automation
4/14/2017 12 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic demonstrates how to sequentially search for and highlight each occurrence of a string within the content
of a text control using Microsoft UI Automation.
Example
The following example obtains a TextPattern object from a text control. A TextPatternRange object, representing
the textual content of the entire document, is then created using the DocumentRange property of this TextPattern.
Two additional TextPatternRange objects are then created for the sequential search and highlight functionality.
///--------------------------------------------------------------------
/// <summary>
/// Starts the target application.
/// </summary>
/// <param name="app">
/// The application to start.
/// </param>
/// <returns>The automation element for the app main window.</returns>
/// <remarks>
/// Three WPF documents, a rich text document, and a plain text document
/// are provided in the Content folder of the TextProvider project.
/// </remarks>
///--------------------------------------------------------------------
private AutomationElement StartApp(string app)
{
// Start application.
Process p = Process.Start(app);
targetResult.Content =
WPFTarget +
" started. \n\nPlease load a document into the target " +
"application and click the 'Find edit control' button above. " +
"\n\nNOTE: Documents can be found in the 'Content' folder of the FindText project.";
targetResult.Background = Brushes.LightGreen;
' Return the automation element for the app main window.
Return AutomationElement.FromHandle(p.MainWindowHandle)
///--------------------------------------------------------------------
/// <summary>
/// Finds the text control in our target.
/// </summary>
/// <param name="src">The object that raised the event.</param>
/// <param name="e">Event arguments.</param>
/// <remarks>
/// Initializes the TextPattern object and event handlers.
/// </remarks>
///--------------------------------------------------------------------
private void FindTextProvider_Click(object src, RoutedEventArgs e)
{
// Set up the conditions for finding the text control.
PropertyCondition documentControl = new PropertyCondition(
AutomationElement.ControlTypeProperty,
ControlType.Document);
PropertyCondition textPatternAvailable = new PropertyCondition(
AutomationElement.IsTextPatternAvailableProperty, true);
AndCondition findControl =
new AndCondition(documentControl, textPatternAvailable);
// Get the Automation Element for the first text control found.
// For the purposes of this sample it is sufficient to find the
// first text control. In other cases there may be multiple text
// controls to sort through.
targetDocument =
targetWindow.FindFirst(TreeScope.Descendants, findControl);
targetResult.Content =
"Text provider found.";
targetResult.Background = Brushes.LightGreen;
// Edit control found so remove the find button from the client.
findEditButton.Visibility = Visibility.Collapsed;
'--------------------------------------------------------------------
' Finds the text control in our target.
' <param name="src">The object that raised the event.</param>
' <param name="e">Event arguments.</param>
' Initializes the TextPattern object and event handlers.
'--------------------------------------------------------------------
Private Sub FindTextProvider_Click( _
ByVal src As Object, ByVal e As RoutedEventArgs)
' Set up the conditions for finding the text control.
Dim documentControl As New PropertyCondition( _
AutomationElement.ControlTypeProperty, ControlType.Document)
Dim textPatternAvailable As New PropertyCondition( _
AutomationElement.IsTextPatternAvailableProperty, True)
Dim findControl As New AndCondition(documentControl, textPatternAvailable)
' Get the Automation Element for the first text control found.
' For the purposes of this sample it is sufficient to find the
' first text control. In other cases there may be multiple text
' controls to sort through.
targetDocument = targetWindow.FindFirst(TreeScope.Descendants, findControl)
' Initialize the document range for the text of the document.
documentRange = targetTextPattern.DocumentRange
' Edit control found so remove the find button from the client.
findEditButton.Visibility = Visibility.Collapsed
' Initialize the client with the current target selection, if any.
NotifySelectionChanged()
///--------------------------------------------------------------------
/// <summary>
/// Handles changes to the search text in the client.
/// </summary>
/// <param name="sender">The object that raised the event.</param>
/// <param name="e">Event arguments.</param>
/// <remarks>
/// Reset all controls if user changes search text
/// </remarks>
///--------------------------------------------------------------------
void SearchString_Change(object sender, TextChangedEventArgs e)
{
int startPoints = documentRange.CompareEndpoints(
TextPatternRangeEndpoint.Start,
searchRange,
TextPatternRangeEndpoint.Start);
int endPoints = documentRange.CompareEndpoints(
TextPatternRangeEndpoint.End,
searchRange,
TextPatternRangeEndpoint.End);
///--------------------------------------------------------------------
/// <summary>
/// Handles the Search button click.
/// </summary>
/// <param name="sender">The object that raised the event.</param>
/// <param name="e">Event arguments.</param>
/// <remarks>Find the text specified in the text box.</remarks>
///--------------------------------------------------------------------
void SearchDirection_Click(object sender, RoutedEventArgs e)
{
Button searchDirection = (Button)sender;
// Search unsuccessful.
if (searchRange == null)
{
// Search string not found at all.
if (documentRangeClone.CompareEndpoints(
TextPatternRangeEndpoint.Start,
searchRangeClone,
TextPatternRangeEndpoint.Start) == 0)
{
targetResult.Content = "Text not found.";
targetResult.Background = Brushes.Wheat;
searchBackwardButton.IsEnabled = false;
searchForwardButton.IsEnabled = false;
}
// End of document (either the start or end of the document
// range depending on search direction) was reached before
// finding another occurence of the search string.
else
{
targetResult.Content = "End of document reached.";
targetResult.Background = Brushes.Wheat;
if (!searchBackward)
{
searchRangeClone.MoveEndpointByRange(
TextPatternRangeEndpoint.Start,
documentRange,
TextPatternRangeEndpoint.End);
searchBackwardButton.IsEnabled = true;
searchForwardButton.IsEnabled = false;
}
else
{
searchRangeClone.MoveEndpointByRange(
TextPatternRangeEndpoint.End,
TextPatternRangeEndpoint.End,
documentRange,
TextPatternRangeEndpoint.Start);
searchBackwardButton.IsEnabled = false;
searchForwardButton.IsEnabled = true;
}
}
searchRange = searchRangeClone;
}
// The search string was found.
else
{
targetResult.Content = "Text found.";
targetResult.Background = Brushes.LightGreen;
}
searchRange.Select();
// Scroll the selection into view and align with top of viewport
searchRange.ScrollIntoView(true);
// The WPF target doesn't show selected text as highlighted unless
// the window has focus.
targetWindow.SetFocus();
}
'--------------------------------------------------------------------
' Handles changes to the search text in the client.
' <param name="sender">The object that raised the event.</param>
' <param name="e">Event arguments.</param>
' Reset all controls if user changes search text
'--------------------------------------------------------------------
Private Sub SearchString_Change( _
ByVal sender As Object, ByVal e As TextChangedEventArgs)
Dim startPoints As Integer = _
documentRange.CompareEndpoints( _
TextPatternRangeEndpoint.Start, searchRange, _
TextPatternRangeEndpoint.Start)
Dim endPoints As Integer = _
documentRange.CompareEndpoints(TextPatternRangeEndpoint.End, _
searchRange, TextPatternRangeEndpoint.End)
' If the starting endpoints of the document range and the search
' range are equivalent then we can search forward only since the
' search range is at the start of the document.
If startPoints = 0 Then
searchForwardButton.IsEnabled = True
searchBackwardButton.IsEnabled = False
' If the ending endpoints of the document range and the search
' range are identical then we can search backward only since the
' search range is at the end of the document.
ElseIf endPoints = 0 Then
searchForwardButton.IsEnabled = False
searchBackwardButton.IsEnabled = True
' Otherwise we can search both directions.
Else
searchForwardButton.IsEnabled = True
searchBackwardButton.IsEnabled = True
End If
'--------------------------------------------------------------------
' Handles the Search button click.
' <param name="sender">The object that raised the event.</param>
' <param name="e">Event arguments.</param>
' <remarks>Find the text specified in the text box.</remarks>
'--------------------------------------------------------------------
Private Sub SearchDirection_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim searchDirection As Button = CType(sender, Button)
' Are we searching backward through the text control?
searchBackward = _
(CType(searchDirection.Tag, traversalDirection) = traversalDirection.Backward)
searchRange.Select()
' Scroll the selection into view and align with top of viewport
searchRange.ScrollIntoView(True)
' The WPF target doesn't show selected text as highlighted unless
' the window has focus.
targetWindow.SetFocus()
See Also
Find and Highlight Text Using UI Automation
Obtain Text Attributes Using UI Automation
4/14/2017 4 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes defined
in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows Automation
API: UI Automation.
This topic shows how to use Microsoft UI Automation to obtain text attributes from a text range. A text range can
correspond to the current location of the caret (or degenerate selection) within a document, a contiguous selection
of text, a collection of disjoint text selections, or the entire textual content of a document.
Example
The following code example demonstrates how to obtain the FontNameAttribute from a text range.
/// -------------------------------------------------------------------
/// <summary>
/// Starts the target application and returns the AutomationElement
/// obtained from the targets window handle.
/// </summary>
/// <param name="exe">
/// The target application.
/// </param>
/// <param name="filename">
/// The text file to be opened in the target application
/// </param>
/// <returns>
/// An AutomationElement representing the target application.
/// </returns>
/// -------------------------------------------------------------------
private AutomationElement StartTarget(string exe, string filename)
{
// Start text editor and load with a text file.
Process p = Process.Start(exe, filename);
return targetApp;
}
''' -------------------------------------------------------------------
''' <summary>
''' Starts the target application and returns the AutomationElement
''' obtained from the targets window handle.
''' </summary>
''' <param name="exe">
''' The target application.
''' </param>
''' <param name="filename">
''' The text file to be opened in the target application
''' </param>
''' <returns>
''' An AutomationElement representing the target application.
''' </returns>
''' -------------------------------------------------------------------
Private Function StartTarget( _
ByVal exe As String, ByVal filename As String) As AutomationElement
' Start text editor and load with a text file.
Dim p As Process = Process.Start(exe, filename)
Return targetApp
End Function
/// -------------------------------------------------------------------
/// <summary>
/// Obtain the text control of interest from the target application.
/// </summary>
/// <param name="targetApp">
/// The target application.
/// </param>
/// <returns>
/// An AutomationElement that represents a text provider..
/// </returns>
/// -------------------------------------------------------------------
private AutomationElement GetTextElement(AutomationElement targetApp)
{
// The control type we're looking for; in this case 'Document'
PropertyCondition cond1 =
new PropertyCondition(
AutomationElement.ControlTypeProperty,
ControlType.Document);
AutomationElement targetTextElement =
targetApp.FindFirst(TreeScope.Descendants, textCondition);
' If targetText is null then a suitable text control was not found.
Return targetTextElement
End Function
/// -------------------------------------------------------------------
/// <summary>
/// Outputs the FontNameAttribute value for a range of text.
/// </summary>
/// <param name="targetTextElement">
/// The AutomationElment that represents a text control.
/// </param>
/// -------------------------------------------------------------------
private void GetFontNameAttribute(AutomationElement targetTextElement)
{
TextPattern textPattern =
targetTextElement.GetCurrentPattern(TextPattern.Pattern) as TextPattern;
if (textPattern == null)
{
// Target control doesn't support TextPattern.
return;
}
if (textAttribute == TextPattern.MixedAttributeValue)
{
// Returns MixedAttributeValue if the value of the
// specified attribute varies over the text range.
Console.WriteLine("Mixed fonts.");
}
else if (textAttribute == AutomationElement.NotSupported)
{
// Returns NotSupported if the specified attribute is
// not supported by the provider or the control.
Console.WriteLine(
"FontNameAttribute not supported by provider.");
}
else
{
Console.WriteLine(textAttribute.ToString());
}
}
}
''' -------------------------------------------------------------------
''' <summary>
''' Outputs the FontNameAttribute value for a range of text.
''' </summary>
''' <param name="targetTextElement">
''' The AutomationElement. that represents the text provider.
''' </param>
''' -------------------------------------------------------------------
Private Sub GetFontNameAttribute( _
ByVal targetTextElement As AutomationElement)
Dim targetTextPattern As TextPattern = _
DirectCast(targetTextElement.GetCurrentPattern( _
TextPattern.Pattern), TextPattern)
The TextPattern control pattern, in tandem with the TextPatternRange class, supports basic text attributes,
properties, and methods. For control-specific functionality that is not supported by TextPattern or TextPatternRange
the AutomationElement, class provides methods for a UI Automation client to access the corresponding native
object model.
See Also
UI Automation TextPattern Overview
Add Content to a Text Box Using UI Automation
Find and Highlight Text Using UI Automation
UI Automation Control Patterns Overview
UI Automation Control Patterns for Clients
Obtain Mixed Text Attribute Details Using UI Automation
Obtain Mixed Text Attribute Details Using UI
Automation
4/14/2017 3 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic shows how to use Microsoft UI Automation to obtain text attribute details from a text range that spans
multiple attribute values. A text range can correspond to the current location of the caret (or degenerate selection)
within a document, a contiguous selection of text, a collection of disjoint text selections, or the entire textual content
of a document.
Example
The following code example demonstrates how to obtain the FontNameAttribute from a text range where
GetAttributeValue returns a MixedAttributeValue object.
///--------------------------------------------------------------------
/// <summary>
/// Display the target selection with attribute details in client.
/// </summary>
/// <param name="selectedText">The current target selection.</param>
///--------------------------------------------------------------------
private void DisplaySelectedTextWithAttributes(string selectedText)
{
targetSelection.Text = selectedText;
// We're only interested in the FontNameAttribute for the purposes
// of this sample.
targetSelectionAttributes.Text =
ParseTextRangeByAttribute(
selectedText, TextPattern.FontNameAttribute);
}
///--------------------------------------------------------------------
/// <summary>
/// Parse the target selection based on the text attribute of interest.
/// </summary>
/// <param name="selectedText">The current target selection.</param>
/// <param name="automationTextAttribute">
/// The text attribute of interest.
/// </param>
/// <returns>
/// A string representing the requested attribute details.
/// </returns>
///--------------------------------------------------------------------
private string ParseTextRangeByAttribute(
string selectedText,
AutomationTextAttribute automationTextAttribute)
{
StringBuilder attributeDetails = new StringBuilder();
// Initialize the current attribute value.
string attributeValue = "";
// Make a copy of the text range.
TextPatternRange searchRangeClone = searchRange.Clone();
// Collapse the range to the starting endpoint.
searchRangeClone.Move(TextUnit.Character, -1);
// Iterate through the range character by character.
for (int x = 1; x <= selectedText.Length; x++)
{
searchRangeClone.Move(TextUnit.Character, 1);
// Get the attribute value of the current character.
string newAttributeValue =
searchRangeClone.GetAttributeValue(automationTextAttribute).ToString();
// If the new attribute value is not equal to the old then report
// the new value along with its location within the range.
if (newAttributeValue != attributeValue)
{
attributeDetails.Append(automationTextAttribute.ProgrammaticName)
.Append(":\n<")
.Append(newAttributeValue)
.Append("> at text range position ")
.AppendLine(x.ToString());
attributeValue = newAttributeValue;
}
}
return attributeDetails.ToString();
}
'--------------------------------------------------------------------
' Display the target selection with attribute details in client.
' <param name="selectedText">The current target selection.</param>
'--------------------------------------------------------------------
Private Sub DisplaySelectedTextWithAttributes(ByVal selectedText As String)
targetSelection.Text = selectedText
' We're only interested in the FontNameAttribute for the purposes
' of this sample.
targetSelectionAttributes.Text = _
ParseTextRangeByAttribute( _
selectedText, TextPattern.FontNameAttribute)
End Sub
'--------------------------------------------------------------------
' Parse the target selection based on the text attribute of interest.
' <param name="selectedText">The current target selection.</param>
' <param name="automationTextAttribute">
' The text attribute of interest.
' A string representing the requested attribute details.
'--------------------------------------------------------------------
Function ParseTextRangeByAttribute( _
ByVal selectedText As String, _
ByVal automationTextAttribute As AutomationTextAttribute) As String
Dim attributeDetails As StringBuilder = New StringBuilder()
' Initialize the current attribute value.
Dim attributeValue As String = ""
' Make a copy of the text range.
Dim searchRangeClone As TextPatternRange = searchRange.Clone()
' Collapse the range to the starting endpoint.
searchRangeClone.Move(TextUnit.Character, -1)
' Iterate through the range character by character.
Dim x As Integer
For x = 1 To selectedText.Length
searchRangeClone.Move(TextUnit.Character, 1)
' Get the attribute value of the current character.
Dim newAttributeValue As String = _
searchRangeClone.GetAttributeValue(automationTextAttribute).ToString()
' If the new attribute value is not equal to the old then report
' the new value along with its location within the range.
If (newAttributeValue <> attributeValue) Then
attributeDetails.Append(automationTextAttribute.ProgrammaticName) _
.Append(":") _
.Append(vbLf) _
.Append("<") _
.Append(newAttributeValue) _
.Append("> at text range position ") _
.AppendLine(x.ToString())
attributeValue = newAttributeValue
End If
Next
Return attributeDetails.ToString()
End Function
The TextPattern control pattern, in tandem with the TextPatternRange class, supports basic text attributes,
properties, and methods. For control-specific functionality that is not supported by TextPattern or
TextPatternRange, the AutomationElement class provides methods for a UI Automation client to access the
corresponding native object model.
See Also
UI Automation TextPattern Overview
Add Content to a Text Box Using UI Automation
Find and Highlight Text Using UI Automation
UI Automation Control Patterns Overview
UI Automation Control Patterns for Clients
Obtain Text Attributes Using UI Automation
Traverse Text Using UI Automation
5/31/2017 9 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic shows how to use Microsoft UI Automation to traverse the textual content of a document by TextUnit
increments.
Example
The following code example demonstrates how to traverse the content of a UI Automation text provider. The Move
method moves the Start and End endpoints of a TextPatternRange. This text range is typically a degenerate range
representing the text insertion point.
NOTE
Since only text-based embedded objects are considered part of the text stream, embedded objects such as images do not
affect Move or its return value.
///--------------------------------------------------------------------
/// <summary>
/// Starts the target application.
/// </summary>
/// <param name="app">
/// The application to start.
/// </param>
/// <returns>The automation element for the app main window.</returns>
/// <remarks>
/// Three WPF documents, a rich text document, and a plain text document
/// are provided in the Content folder of the TextProvider project.
/// </remarks>
///--------------------------------------------------------------------
private AutomationElement StartApp(string app)
{
// Start application.
Process p = Process.Start(app);
targetResult.Content =
WPFTarget +
" started. \n\nPlease load a document into the target " +
"application and click the 'Find edit control' button above. " +
"\n\nNOTE: Documents can be found in the 'Content' folder of the FindText project.";
targetResult.Background = Brushes.LightGreen;
'--------------------------------------------------------------------
' Starts the target application.
' <param name="app">
' The application to start.
' <returns>The automation element for the app main window.</returns>
' Three WPF documents, a rich text document, and a plain text document
' are provided in the Content folder of the TextProvider project.
'--------------------------------------------------------------------
Private Function StartApp(ByVal app As String) As AutomationElement
' Start application.
Dim p As Process = Process.Start(app)
' Return the automation element for the app main window.
Return AutomationElement.FromHandle(p.MainWindowHandle)
// Get the Automation Element for the first text control found.
// For the purposes of this sample it is sufficient to find the
// first text control. In other cases there may be multiple text
// controls to sort through.
targetDocument =
targetWindow.FindFirst(TreeScope.Descendants, findControl);
targetResult.Content =
"Text provider found.";
targetResult.Background = Brushes.LightGreen;
// Edit control found so remove the find button from the client.
findEditButton.Visibility = Visibility.Collapsed;
'--------------------------------------------------------------------
' Finds the text control in our target.
' <param name="src">The object that raised the event.</param>
' <param name="e">Event arguments.</param>
' Initializes the TextPattern object and event handlers.
'--------------------------------------------------------------------
Private Sub FindTextProvider_Click( _
ByVal src As Object, ByVal e As RoutedEventArgs)
' Set up the conditions for finding the text control.
Dim documentControl As New PropertyCondition( _
AutomationElement.ControlTypeProperty, ControlType.Document)
Dim textPatternAvailable As New PropertyCondition( _
AutomationElement.IsTextPatternAvailableProperty, True)
Dim findControl As New AndCondition(documentControl, textPatternAvailable)
' Get the Automation Element for the first text control found.
' For the purposes of this sample it is sufficient to find the
' first text control. In other cases there may be multiple text
' controls to sort through.
targetDocument = targetWindow.FindFirst(TreeScope.Descendants, findControl)
' Initialize the document range for the text of the document.
documentRange = targetTextPattern.DocumentRange
' Edit control found so remove the find button from the client.
findEditButton.Visibility = Visibility.Collapsed
' Initialize the client with the current target selection, if any.
NotifySelectionChanged()
///--------------------------------------------------------------------
/// <summary>
/// Handles the navigation item selected event.
/// </summary>
/// <param name="sender">The object that raised the event.</param>
/// <param name="e">Event arguments.</param>
///--------------------------------------------------------------------
private void NavigationUnit_Change(object sender, SelectionChangedEventArgs e)
{
ComboBox cb = (ComboBox)sender;
navigationUnit = (TextUnit)cb.SelectedValue;
}
///--------------------------------------------------------------------
/// <summary>
/// Handles the Navigate button click event.
/// </summary>
/// <param name="sender">The object that raised the event.</param>
/// <param name="e">Event arguments.</param>
///--------------------------------------------------------------------
private void Navigate_Click(object sender, RoutedEventArgs e)
{
Button moveSelection = (Button)sender;
'--------------------------------------------------------------------
' Handles the Navigate button click event.
' <param name="sender">The object that raised the event.</param>
' <param name="e">Event arguments.</param>
'--------------------------------------------------------------------
Private Sub Navigate_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim moveSelection As Button = CType(sender, Button)
Dim navDirection As Integer
' Which direction is the user searching through the text control?
If (CType(moveSelection.Tag, traversalDirection) = traversalDirection.Forward) Then
navDirection = 1
Else
navDirection = -1
End If
' Iterate throught the ranges for a text control that supports
' multiple selections and move the selections the specified text
' unit and direction.
Dim textRange As TextPatternRange
For Each textRange In selectionRanges
textRange.Move(navigationUnit, navDirection)
textRange.Select()
Next textRange
' The WPF target doesn't show selected text as highlighted unless
' the window has focus.
targetDocument.SetFocus()
Any method using TextUnit will defer to the next largest TextUnit supported if the given TextUnit is not supported
by the control.
See Also
UI Automation TextPattern Overview
Add Content to a Text Box Using UI Automation
Find and Highlight Text Using UI Automation
UI Automation Control Patterns Overview
UI Automation Control Patterns for Clients
Access Embedded Objects Using UI Automation
4/14/2017 12 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic shows how Microsoft UI Automation can be used to expose objects embedded within the content of a
text control.
NOTE
Embedded objects can include images, hyperlinks, buttons, tables, or ActiveX controls.
Embedded objects are considered children of the UI Automation text provider. This allows them to be exposed
through the same UI Automation tree structure as all other user interface (UI) elements. Functionality, in turn, is
exposed through the control patterns typically required by the embedded objects control type (for example, since
hyperlinks are text-based they will support TextPattern).
A sample document with textual content, ("Did You Know?") and two embedded objects (a picture of a whale and
a text hyperlink), used as a target for the code examples.
Example
The following code example demonstrates how to retrieve a collection of embedded objects from within a UI
Automation text provider. For the sample document provided in the introduction, two objects would be returned
(an image element and a text element).
NOTE
The image element should have some intrinsic text associated with it that describes the image, typically in its NameProperty
(for example, "A blue whale."). However, when a text range spanning the image object is obtained, neither the image nor this
descriptive text is returned in the text stream.
///--------------------------------------------------------------------
/// <summary>
/// Starts the target application.
/// </summary>
/// <param name="app">
/// The application to start.
/// </param>
/// <returns>The automation element for the app main window.</returns>
/// <remarks>
/// Three WPF documents, a rich text document, and a plain text document
/// are provided in the Content folder of the TextProvider project.
/// </remarks>
///--------------------------------------------------------------------
private AutomationElement StartApp(string app)
{
// Start application.
Process p = Process.Start(app);
targetResult.Content =
WPFTarget +
" started. \n\nPlease load a document into the target " +
"application and click the 'Find edit control' button above. " +
"\n\nNOTE: Documents can be found in the 'Content' folder of the FindText project.";
targetResult.Background = Brushes.LightGreen;
'--------------------------------------------------------------------
' Starts the target application.
' <param name="app">
' The application to start.
' <returns>The automation element for the app main window.</returns>
' Three WPF documents, a rich text document, and a plain text document
' are provided in the Content folder of the TextProvider project.
'--------------------------------------------------------------------
Private Function StartApp(ByVal app As String) As AutomationElement
' Start application.
Dim p As Process = Process.Start(app)
' Return the automation element for the app main window.
Return AutomationElement.FromHandle(p.MainWindowHandle)
// Get the Automation Element for the first text control found.
// For the purposes of this sample it is sufficient to find the
// first text control. In other cases there may be multiple text
// controls to sort through.
targetDocument =
targetWindow.FindFirst(TreeScope.Descendants, findControl);
targetResult.Content =
"Text provider found.";
targetResult.Background = Brushes.LightGreen;
// Edit control found so remove the find button from the client.
findEditButton.Visibility = Visibility.Collapsed;
'--------------------------------------------------------------------
' Finds the text control in our target.
' <param name="src">The object that raised the event.</param>
' <param name="e">Event arguments.</param>
' Initializes the TextPattern object and event handlers.
'--------------------------------------------------------------------
Private Sub FindTextProvider_Click( _
ByVal src As Object, ByVal e As RoutedEventArgs)
' Set up the conditions for finding the text control.
Dim documentControl As New PropertyCondition( _
AutomationElement.ControlTypeProperty, ControlType.Document)
Dim textPatternAvailable As New PropertyCondition( _
AutomationElement.IsTextPatternAvailableProperty, True)
Dim findControl As New AndCondition(documentControl, textPatternAvailable)
' Get the Automation Element for the first text control found.
' For the purposes of this sample it is sufficient to find the
' first text control. In other cases there may be multiple text
' controls to sort through.
targetDocument = targetWindow.FindFirst(TreeScope.Descendants, findControl)
' Initialize the document range for the text of the document.
documentRange = targetTextPattern.DocumentRange
' Edit control found so remove the find button from the client.
findEditButton.Visibility = Visibility.Collapsed
' Initialize the client with the current target selection, if any.
NotifySelectionChanged()
///--------------------------------------------------------------------
/// <summary>
/// Gets the children of the target selection.
/// </summary>
/// <param name="sender">The object that raised the event.</param>
/// <param name="e">Event arguments.</param>
///--------------------------------------------------------------------
private void GetChildren_Click(object sender, RoutedEventArgs e)
{
// Obtain an array of child elements.
AutomationElement[] textProviderChildren;
try
{
textProviderChildren = searchRange.GetChildren();
}
catch (ElementNotAvailableException)
{
// TODO: error handling.
return;
}
Example
The following code example demonstrates how to obtain a text range from an embedded object within a UI
Automation text provider. The text range retrieved is an empty range where the starting endpoint follows " ocean.
(space)" and the ending endpoint precedes the closing "." representing the embedded hyperlink (as shown by the
image provided in the introduction). Even though this is an empty range, it is not considered a degenerate range
because it has a non-zero span.
NOTE
TextPattern can retrieve a text-based embedded object such as a hyperlink; however, a secondary TextPattern will have to be
obtained from the embedded object to expose its full functionality.
/// -------------------------------------------------------------------
/// <summary>
/// Obtains a text range spanning an embedded child
/// of a document control and displays the content of the range.
/// </summary>
/// <param name="targetTextElement">
/// The AutomationElment that represents a text control.
/// </param>
/// -------------------------------------------------------------------
private void GetRangeFromChild(AutomationElement targetTextElement)
{
TextPattern textPattern =
targetTextElement.GetCurrentPattern(TextPattern.Pattern)
as TextPattern;
if (textPattern == null)
{
// Target control doesn't support TextPattern.
return;
}
See Also
UI Automation TextPattern Overview
UI Automation Control Patterns Overview
UI Automation Control Patterns for Clients
Add Content to a Text Box Using UI Automation
Find and Highlight Text Using UI Automation
UI Automation Control Types
4/14/2017 1 min to read Edit Online
Note This documentation is intended for .NET Framework developers who want to use the managed UI
Automation classes defined in the System.Windows.Automation namespace. For the latest information about UI
Automation, see Windows Automation API: UI Automation.
This section contains information about support for control types in Microsoft UI Automation.
In This Section
UI Automation Control Types Overview
UI Automation Support for the Button Control Type
UI Automation Support for the Calendar Control Type
UI Automation Support for the CheckBox Control Type
UI Automation Support for the ComboBox Control Type
UI Automation Support for the DataGrid Control Type
UI Automation Support for the DataItem Control Type
UI Automation Support for the Document Control Type
UI Automation Support for the Edit Control Type
UI Automation Support for the Group Control Type
UI Automation Support for the Header Control Type
UI Automation Support for the HeaderItem Control Type
UI Automation Support for the Hyperlink Control Type
UI Automation Support for the Image Control Type
UI Automation Support for the List Control Type
UI Automation Support for the ListItem Control Type
UI Automation Support for the Menu Control Type
UI Automation Support for the MenuBar Control Type
UI Automation Support for the MenuItem Control Type
UI Automation Support for the Pane Control Type
UI Automation Support for the ProgressBar Control Type
UI Automation Support for the RadioButton Control Type
UI Automation Support for the ScrollBar Control Type
UI Automation Support for the Separator Control Type
UI Automation Support for the Slider Control Type
UI Automation Support for the Spinner Control Type
UI Automation Support for the SplitButton Control Type
UI Automation Support for the StatusBar Control Type
UI Automation Support for the Tab Control Type
UI Automation Support for the TabItem Control Type
UI Automation Support for the Table Control Type
UI Automation Support for the Text Control Type
UI Automation Support for the Thumb Control Type
UI Automation Support for the TitleBar Control Type
UI Automation Support for the ToolBar Control Type
UI Automation Support for the ToolTip Control Type
UI Automation Support for the Tree Control Type
UI Automation Support for the TreeItem Control Type
UI Automation Support for the Window Control Type
Reference
ControlType
See Also
UI Automation Control Patterns
UI Automation Control Types Overview
4/14/2017 2 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
Microsoft UI Automation control types are well-known identifiers that can be used to indicate what kind of
control a particular element represents, such as a combo box or a button.
Having a well-known identifier makes it easier for assistive technology devices to determine what types of
controls are available in the user interface (UI) and how to interact with the controls.
See Also
ControlType
UI Automation Support for the Button Control Type
4/14/2017 3 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the Button control type. In UI Automation, a
control type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values, control
patterns, and UI Automation events.
A button is an object that a user interacts with to perform an action such as the OK and Cancel buttons on a dialog
box. The button control is a simple control to expose because it maps to a single command that the user wishes to
complete.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the Button control type. The UI Automation requirements apply to all button controls, whether Windows
Presentation Foundation (WPF), Win32, or Windows Forms.
Button Button
- Image (0 or more)
- Text (0 or more)
HelpTextProperty See notes. The Help Text can indicate what the end
result of activating the button will be.
This is typically the same type of
information presented through a
ToolTip.
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the Calendar control type. In UI Automation, a
control type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values, control
patterns, and UI Automation events.
Calendar controls allow a user to easily determine the date and select other dates.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the Calendar control type. The UI Automation requirements apply to all calendar controls, whether Windows
Presentation Foundation (WPF), Win32, or Windows Forms.
Calendar Calendar
Calendar controls can be represented in many different forms within the user interface. The only guaranteed
controls to be in the control view of the UI Automation tree are the data grid, header, header item, and list item
controls.
See Also
Calendar
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the CheckBox Control
Type
4/14/2017 3 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about Microsoft UI Automation support for the CheckBox control type. In UI
Automation, a control type is a set of conditions that a control must meet in order to use the ControlTypeProperty
property. The conditions include specific guidelines for UI Automation tree structure, UI Automation property
values and control patterns.
A check box is an object used to indicate a state that users can interact with to cycle through that state. Check boxes
either present a binary (Yes/No), (On/Off), or tertiary (On, Off, Indeterminate) option to the user.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the CheckBox control type. The UI Automation requirements apply to all check box controls, whether Windows
Presentation Foundation (WPF), Win32, or Windows Forms.
CheckBox CheckBox
NOTE
Check boxes never have child elements in the control or content view. If the control does need to contain child elements this
indicates that another control type should be used.
Default Action
The default action of the check box is to cause a radio button to become focused and toggle its current state. As
mentioned previously, check boxes either present a binary (Yes/No) (On/Off) decision to the user or a tertiary (On,
Off, Indeterminate). If the check box is binary the default action causes the "on" state to become "off" or the "off"
state to become "on". In a tertiary state check box the default action cycles through the states of the check box in
the same order as if the user had sent successive mouse clicks to the control.
See Also
CheckBox
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the ComboBox Control
Type
4/14/2017 4 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the ComboBox control type. In UI Automation, a
control type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values, control
patterns, and UI Automation events.
A combo box is a list box combined with a static control or an edit control that displays the currently selected item
in the list box portion of the combo box. The list box portion of the control is displayed at all times or only appears
when the user selects the drop-down arrow (which is a push button) next to the control. If the selection field is an
edit control, the user can enter information that is not in the list; otherwise, the user can only select items in the list.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the ComboBox control type. The UI Automation requirements apply to all combo box controls, whether Windows
Presentation Foundation (WPF), Win32, or Windows Forms.
ComboBox ComboBox
The edit control in the control view of the combo box is necessary only if the combo box can be edited to take any
input, as is the case of the combo box in the Run dialog box.
HelpTextProperty See notes. The help text for combo box controls
should explain why the user is being
asked to choose an option from the
combo box. The text is similar to
information presented through a
tooltip. For example, "Select an item to
set the display resolution of your
monitor."
NameProperty See notes. The combo box control typically gets its
name from a static text control.
Required Events
The following table lists the UI Automation events required to be supported by all combo box controls. For more
information on events, see UI Automation Events Overview.
See Also
ComboBox
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the DataGrid Control
Type
4/14/2017 5 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about Microsoft UI Automation support for the DataGrid control type. In UI
Automation, a control type is a set of conditions that a control must meet in order to use the ControlType
property. The conditions include specific guidelines for UI Automation tree structure, UI Automation property
values and control patterns.
The DataGrid control type lets a user easily work with items that contain metadata represented in columns. Data
grid controls have rows of items and columns of information about those items. A List View control in Microsoft
Vista Explorer is an example that supports the DataGrid control type.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the DataGrid control type. The UI Automation requirements apply to all data grid controls, whether Windows
Presentation Foundation (WPF), Win32, or Windows Forms.
DataGrid DataGrid
NameProperty See notes. The data grid control typically gets the
value for its Name property from a
static text label. If there is not a static
text label an application developer must
assign a value to for the Name
property. The value of the Name
property must never be the textual
contents of the edit control.
Data items within the data grid containers will support at a minimum:
Selection Item control pattern (if the data grid is selectable)
Scroll Item control pattern (if the data grid is scrollable)
Grid Item control pattern
Table Item control pattern
The control view and the content view of the UI Automation tree that pertains to the List View control is displayed
below. The control patterns for each automation element are shown in parentheses.
*The preceding example shows a DataGrid that contains multiple levels of controls. The Group ("Contoso") control
contains two DataItem controls ("Accounts Receivable.doc" and "Accounts Payable.doc"). A DataGrid/GridItem pair
is independent of a pair at another level. The DataItem controls under a Group can also be exposed as a ListItem
control type, enabling them to be presented more clearly as selectable objects, rather than as simple data elements.
This example does not include the sub-elements of the grouped data items.
See Also
DataGrid
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the DataItem Control
Type
4/14/2017 5 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about Microsoft UI Automation support for the DataItem control type. In UI
Automation a control type is a set of conditions that a control must meet in order to use the ControlTypeProperty
property. The conditions include specific guidelines for UI Automation tree structure, UI Automation property
values and control patterns.
An entry in a Contacts list is an example of a data item control. A data item control contains information that is of
interest to an end user. It is more complicated than the simple list item because it contains richer information.
The following sections define the required UI Automation tree structure, properties, control patterns, and events
for the DataItem control type. The UI Automation requirements apply to all data item controls, whether Windows
Presentation Foundation (WPF), Win32, or Windows Forms.
DataItem DataItem
- Varies (0 or more; can be structured in hierarchy) - Varies (0 or more; can be structured in hierarchy)
A data item element in a data grid can host a variety of objects, including another layer of data items, or specific
grid elements such as text, images, or edit controls. If the data item element has a specific object role, the element
should be exposed as a specific control type; for example, a ListItem control type for a selectable data item in the
grid.
The Control View and the Content View of the UI Automation tree that pertains to the data item control is
displayed below. The control patterns for each automation element are shown in parentheses. The Group
"Contoso" is also part of the grid of the Data Grid host control.
See Also
DataItem
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the Document Control
Type
4/14/2017 3 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the Document control type. In UI Automation, a
control type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values, and control
patterns.
Document controls let a user view and manipulate multiple pages of text. Unlike edit controls which only support a
simple line of unformatted text, document controls can host text that is richly styled and formatted.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the Document control type. The UI Automation requirements apply to all document controls, whether Windows
Presentation Foundation (WPF), Win32, or Windows Forms.
Document Document
- Varies - Varies
See Also
Document
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the Edit Control Type
4/14/2017 4 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the Edit control type. In UI Automation, a control
type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values, and control
patterns.
Edit controls enable a user to view and edit a simple line of text without rich formatting support.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the Edit control type. The UI Automation requirements apply to all edit controls, whether Windows Presentation
Foundation (WPF), Win32, or Windows Forms.
Edit Edit
The controls that implement the Edit control type will always have zero scroll bars in the control view of the UI
Automation tree because it is a single-line control. The single line of text may wrap in some layout scenarios. The
Edit control type is best suited for holding small amounts of editable or selectable text.
ValueProperty property-changed event. Depends If the control supports the range Value
control pattern, it must support this
event.
See Also
Edit
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the Group Control Type
4/14/2017 3 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the Group control type. In UI Automation, a
control type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values, and UI
Automation control patterns.
The group control represents a node within a hierarchy. The Group control type creates a separation in the UI
Automation tree so items that are grouped together have a logical division within the UI Automation tree.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the Group control type. The UI Automation requirements apply to all group controls, whether Windows
Presentation Foundation (WPF), Win32, or Windows Forms.
Group Group
Typically group controls will have the UI Automation Support for the ListItem Control Type, UI Automation Support
for the TreeItem Control Type, or UI Automation Support for the DataItem Control Type control types found
underneath them in the subtree. Because 'Group' is a generic container, it is possible for any type of control to be
under the Group control in the tree.
See Also
Group
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the Header Control Type
4/14/2017 2 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the Header control type. In UI Automation, a
control type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values and control
patterns.
The header control provides a visual container for the labels for rows or columns of information.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the Header control type. The UI Automation requirements apply to all header controls, whether Windows
Presentation Foundation (WPF), Win32, or Windows Forms.
Header None
- HeaderItem (1 or more)
Header controls always have 1 or more children in the control view of the UI Automation tree.
Header controls have zero children in the content view of the UI Automation tree.
See Also
Header
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the HeaderItem Control
Type
4/14/2017 2 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the HeaderItem control type. In UI Automation, a
control type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values and control
patterns.
The HeaderItem control type provides a visual label for a row or column of information.
Header item controls are examples of controls that implement the HeaderItem control type. The UI Automation
requirements in the following sections apply to all header controls, whether Windows Presentation Foundation
(WPF), Win32, or Windows Forms.
HeaderItem None
See Also
HeaderItem
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the Hyperlink Control
Type
4/14/2017 3 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the Hyperlink control type. In UI Automation, a
control type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values and control
patterns.
Hyperlink controls enable a user to navigate within a page, from one page to another page, and open windows.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the Hyperlink control type. The UI Automation requirements apply to all hyperlink controls, whether Windows
Presentation Foundation (WPF), Win32, or Windows Forms.
Hyperlink Hyperlink
See Also
Hyperlink
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the Image Control Type
4/14/2017 4 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the Image control type. In UI Automation, a
control type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values and control
patterns.
Image controls used as icons, informational graphics, and charts will support the Image control type. Controls used
as background or watermark images will not support the Image control type.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the Image control type. The UI Automation requirements apply to all image controls, whether Windows
Presentation Foundation (WPF), Win32, or Windows Forms.
See Also
Image
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the List Control Type
4/14/2017 5 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the List control type. In UI Automation, a control
type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values and control
patterns.
The List control type provides a way to organize a flat group or groups of items and allows a user to select one or
more of those items. The List control type has a loose restriction on what types of child elements it may contain.
This enables UI Automation providers to support a well-known element for selection containers.
The UI Automation requirements in the following sections apply to all controls that implement the List control type,
whether Windows Presentation Foundation (WPF), Win32, or Windows Forms. List container controls are an
example of controls that implement the List control type.
Contains the elements that correspond to controls. Removes redundant information from the tree so that
assistive technologies work with the smallest set of
meaningful information to the end user.
List List
The control view for a control that implements the List control type (such as a list control) consists of:
Zero or more items within the list control (items can be based on the List Item or Data Item control types)
Zero or more group controls within a list control
Zero, one, or two scroll bar controls
-
The content view of a control that implements the List control type (such as a list control) consists of:
Zero or more items within the list control (items can be based on the List Item or Data Item control types)
Zero or more groups within the list control
A list control must not have items that have a hierarchical relationship other than being grouped together. If the
items have children in the UI Automation tree, then the list container should be based on the Tree control type.
The selectable items within the list control will be available from the descendants in the UI Automation tree of the
list control. All items within the list control must belong to the same selection group. The selectable items in the list
should be exposed as ListItem (instead of DataItem) control types.
HelpTextProperty See notes. The Help text for list controls should
explain why the user is being asked to
make a choice from a list of options. For
example, "Selection an item from this
list will set the display resolution for
your monitor."
See Also
List
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the ListItem Control Type
4/14/2017 4 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the ListItem control type. In UI Automation, a
control type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values and control
patterns.
List item controls are an example of controls that implement the ListItem control type.
The following sections define the required UI Automation tree structure, properties, control patterns, and events
for the ListItem control type. The UI Automation requirements apply to all list controls, whether Windows
Presentation Foundation (WPF), Win32, or Windows Forms.
ListItem ListItem
- Image (0 or more)
- Text (0 or more)
- Edit (0 or more)
The children of a list item control within the content view of the UI Automation tree must always be "0". If the
structure of the control is such that other items are contained underneath the list item then it should follow the
requirements for the UI Automation Support for the TreeItem Control Type control type.
See Also
ListItem
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the Menu Control Type
4/14/2017 2 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about Microsoft UI Automation support for the Menu control type. It describes the
control's Microsoft UI Automation tree structure and provides the properties and control patterns for specific
control scenarios.
A menu control allows hierarchal organization of elements associated with commands and event handlers. In a
typical Microsoft Windows application, a menu bar contains several menu buttons (such as File, Edit, and
Window), and each menu button displays a menu. A menu contains a collection of menu items (such as New,
Open, and Close), which can be expanded to display additional menu items or to perform a specific action when
clicked.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the Menu control type. The UI Automation requirements apply to all list controls, whether Windows Presentation
Foundation (WPF), Win32, or Windows Forms.
Menu controls always appear in the control view and the content view of the UI Automation tree. Menu control
types should appear under the control that their information is referring to. UI Automation clients must listen for
MenuOpenedEvent to ensure that they consistently obtain information conveyed by menu controls. Context menu
controls are a special case. They appear as children of the Desktop.
See Also
Menu
UI Automation Control Patterns Overview
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the MenuBar Control
Type
4/14/2017 3 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the MenuBar control type. In UI Automation, a
control type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values and control
patterns.
Menu bar controls are an example of controls that implement the MenuBar control type. Menu bars provide a
means for users to activate commands and options contained in an application.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the MenuBar control type. The UI Automation requirements apply to all list controls, whether Windows
Presentation Foundation (WPF), Win32, or Windows Forms.
MenuBar MenuBar
Menu bar controls can contain other controls such as edit controls and combo boxes within its structure. These
additional controls correspond to the "other controls" listed above in the control and content views.
NameProperty See notes. The menu bar control does not need a
name unless an application has more
than one menu bar. If there is more
than one menu bar in an application,
then this property should be used to
expose distinguishing names, such as
"Formatting" or "Outlining."
See Also
MenuBar
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the MenuItem Control
Type
4/14/2017 4 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about Microsoft UI Automation support for the MenuItem control type. It describes
the control's Microsoft UI Automation tree structure and provides the properties and control patterns that are
required for the MenuItem control type.
A menu control allows hierarchal organization of elements associated with commands and event handlers. In a
typical Microsoft Windows application, a menu bar contains several menu items (such as File, Edit, and Window),
and each menu item displays a menu. A menu contains a collection of menu items (such as New, Open, and
Close), which can be expanded to display additional menu items or perform a specific action when clicked. A menu
item can be hosted in a menu, menu bar, or tool bar.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the MenuItem control type. The UI Automation requirements apply to all list controls, whether Windows
Presentation Foundation (WPF), Win32, or Windows Forms.
The control view of the menu item control has the UI Automation tree structure shown above. Note that the Help
menu item is inlcluded to better illustrate the structure in a typical menu to submenu hierarchy.
For the content view, Menu is absent from the UI Automation tree because it does not convey meaningful
information to the end user.
Legacy Issues
Toggle Pattern will only be supported when the Win32 menu item is checked and can be programmatically
determined necessary to support Toggle Pattern. Because the Win32 menu item does not expose whether it has
the ability to be checked, Invoke Pattern will be supported when the menu item is not checked. An exception will be
made to always support Invoke Pattern even for menu items that should only support Toggle Pattern. This is so
clients do not become confused that an element that was supporting Invoke Pattern (when menu item was
unchecked) no longer supports the pattern once it becomes checked.
See Also
MenuItem
UI Automation Control Patterns Overview
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the Pane Control Type
4/14/2017 3 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the Pane control type. In UI Automation, a control
type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values and control
patterns.
The Pane control type is used to represent an object within a frame or document window. Users can navigate
between pane controls and within the contents of the current pane, but cannot navigate between items in different
panes. Thus, pane controls represent a level of grouping lower than windows or documents, but above individual
controls. The user navigates between panes by pressing TAB, F6, or CTRL+TAB, depending on the context. No
specific keyboard navigation is required by the Pane control type.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the Pane control type. The UI Automation requirements apply to all list controls, whether Windows Presentation
Foundation (WPF), Win32, or Windows Forms.
Pane Pane
NameProperty See notes. The value for this property must always
be a clear, concise and meaningful title.
Pane - Pane
Tree (Scroll Pattern) - Tree (Scroll Pattern)
- TreeItem
TreeItem - Pane
Pane - Edit
- (Scroll Pattern)
Edit (Scroll Pattern
See Also
Pane
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the ProgressBar Control
Type
4/14/2017 3 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the ProgressBar control type. In UI Automation, a
control type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values, control
patterns, and UI Automation events.
Progress bar controls are an example of controls that implement the ProgressBar control type. Progress bar
controls are used to indicate the progress of a lengthy operation. The control consists of a rectangle that is
gradually filled with the system highlight color as an operation progresses.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the ProgressBar control type. The UI Automation requirements apply to all list controls, whether Windows
Presentation Foundation (WPF), Win32, or Windows Forms.
ProgressBar ProgressBar
The progress bar controls do not have any children in the control or content view of the UI Automation tree.
See Also
ProgressBar
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the RadioButton Control
Type
4/14/2017 3 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the RadioButton control type. In UI Automation, a
control type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values and control
patterns.
A radio button consists of a round button and application-defined text (a label), an icon, or a bitmap that indicates a
choice the user can make by selecting the button. An application typically uses radio buttons in a group box to
permit the user to choose from a set of related, but mutually exclusive options. For example, the application might
present a group of radio buttons from which the user can select a format preference for text selected in the client
area. The user could select a left-aligned, right-aligned, or centered format by selecting the corresponding radio
button. Typically, the user can select only one option at a time from a set of radio buttons.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the RadioButton control type. The UI Automation requirements apply to all list controls, whether Windows
Presentation Foundation (WPF), Win32, or Windows Forms.
RadioButton RadioButton
See Also
RadioButton
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the ScrollBar Control
Type
4/14/2017 3 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the ScrollBar control type. In UI Automation, a
control type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values and control
patterns.
Scroll bar controls enable a user to scroll content within a window or item container. The control is made up of a
set of buttons and a thumb control.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the ScrollBar control type. The UI Automation requirements apply to all list controls, whether Windows
Presentation Foundation (WPF), Win32, or Windows Forms.
ScrollBar Not applicable. The scroll bar control does not contain
content.
- Button (2 or 4)
- Thumb (0 or1)
The scroll bar control always has three to five children. Because the subtree has more than one button control, you
must set a specific AutomationIdProperty value to each item to make them discoverable for test automation tools.
ClickablePointProperty Not a number. The scroll bar control does not have
clickable points.
See Also
ScrollBar
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the Separator Control
Type
4/14/2017 2 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the Separator control type. In UI Automation, a
control type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values, and control
patterns.
Separator controls are used to visually divide a space into two regions. For example, a separator control can be a
bar that defines two panes in a window. If the separator can be moved, the control should be exposed as Thumb in
control type.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the Separator control type. The UI Automation requirements apply to all list controls, whether Windows
Presentation Foundation (WPF), Win32, or Windows Forms.
See Also
Separator
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the Slider Control Type
4/14/2017 3 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the Slider control type. In UI Automation, a
control type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values and control
types.
The Slider control is a composite control with buttons that enable a user with a mouse to set a numerical range or
select from a set of items.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the Slider control type. The UI Automation requirements apply to all slider controls, whether Windows Presentation
Foundation (WPF), Win32, or Windows Forms.
Slider Slider
See Also
Slider
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the Spinner Control Type
4/14/2017 3 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the Spinner control type. In UI Automation, a
control type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values and control
patterns.
Spinner controls are used to select from a domain of items or a range of numbers.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the Spinner control type. The UI Automation requirements apply to all spinner controls, whether Windows
Presentation Foundation (WPF), Win32, or Windows Forms.
Spinner Spinner
- Edit (0 or 1)
- Button (2)
Spinner Spinner
To ensure that the two buttons in the control view subtree can be distinguished by automated test tools, assign the
SmallIncrement or SmallDecrement``AutomationId as appropriate. For some implementations, the associated Edit
control may be a peer of the Spinner control.
See Also
Spinner
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the SplitButton Control
Type
4/14/2017 3 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the SplitButton control type. In UI Automation, a
control type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values and control
patterns.
The split button control enables the ability to perform an action on a control and expand the control to see a list of
other possible actions that can be performed.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the SplitButton control type. The UI Automation requirements apply to all split button controls, whether Windows
Presentation Foundation (WPF), Win32, or Windows Forms.
SplitButton SplitButton
HelpTextProperty See notes. The help text can indicate the result of
activating the split button, which is
typically the same type of information
presented through a tooltip.
The Control View and the Content View of the UI Automation tree that pertains to the data grid and split button
controls is displayed below. The control patterns for each automation element are shown in parentheses.
Menu Menu
MenuItem MenuItem
See Also
SplitButton
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the StatusBar Control
Type
4/14/2017 3 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the StatusBar control type. In UI Automation, a
control type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values and control
patterns.
A status bar control displays information about an object being viewed in a window of an application, the object's
component, or contextual information that relates to that object's operation within your application.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the StatusBar control type. The UI Automation requirements apply to all status bar controls, whether Windows
Presentation Foundation (WPF), Win32, or Windows Forms.
StatusBar StatusBar
NameProperty See notes. The status bar control does not need a
name unless more than one is used
within an application. In this case,
distinguish each bar with names such as
"Internet Status" or "Application Status."
See Also
StatusBar
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the Tab Control Type
4/14/2017 3 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the Tab control type. In UI Automation, a control
type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values and UI
Automation. control patterns.
A tab control is analogous to the dividers in a notebook or the labels in a file cabinet. By using a tab control, an
application can define multiple pages for the same area of a window or dialog box.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the Tab control type. The UI Automation requirements apply to all tab controls, whether Windows Presentation
Foundation (WPF), Win32, or Windows Forms.
Tab Tab
Button (0 or 2)
Tab controls have child UI Automation elements based on the Tab Item control type. When tab items are grouped
(for example, as in Microsoft Office 2007 applications) the Tab control type can also host Groups control types for
the grouped tab items, as the following tree structure shows.
CONTROL VIEW CONTENT VIEW
Tab Tab
Button (0 or 2)
See Also
Tab
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the TabItem Control Type
4/14/2017 2 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the TabItem control type. In UI Automation, a
control type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values and control
patterns.
A tab item control is used as the control within a tab control that selects a specific page to be shown in a window.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the TabItem control type. The UI Automation requirements apply to all tab item controls, whether Windows
Presentation Foundation (WPF), Win32, or Windows Forms.
TabItem TabItem
Image (0 or 1) Pane
Text
Pane Various controls (0 or more)
See Also
TabItem
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the Table Control Type
4/14/2017 3 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the Table control type. In UI Automation, a
control type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values and control
patterns.
Table controls contain rows and columns of text, and optionally, row headers and column headers.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the Table control type. The UI Automation requirements apply to all table controls, whether Windows Presentation
Foundation (WPF), Win32, or Windows Forms.
Table Table
If a table control has row or column headers, they must be exposed in the Control View of the UI Automation tree.
The Content View does not need to expose this information because it can be accessed using the TablePattern.
NameProperty See notes. The table control typically gets its name
from a static text label. If there is no
static text label, you must assign a
Name property that must always be
available to explain the purpose of the
table.
IGridItemProvider Yes (required with child objects) The inner objects of a table should
support both the GridItem and
TableItem control patterns. The table
itself need not support the GridItem or
TableItem control patterns unless the
table is part of another table.
CONTROL PATTERN SUPPORT NOTES
ITableItemProvider Yes (required with child objects) The inner objects of a table should
support both the GridItem and
TableItem control patterns. The table
itself need not support the GridItem or
TableItem control patterns unless the
table is part of another table.
See Also
Table
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the Text Control Type
4/14/2017 3 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the Text control type. In UI Automation, a control
type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values and control
patterns.
Text controls are the basic user interface item that represents a piece of text on the screen.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the Text control type. The UI Automation requirements apply to all text controls, whether Windows Presentation
Foundation (WPF), Win32, or Windows Forms.
A text control can be used alone as a label or as static text on a form. It can also be contained within the structure of
a:
ListItem
TreeItem
DataItem
Text controls may not be in the Content View of the UI Automation tree because text is often displayed through the
NameProperty of another control. For example the text that is used to label a Combo Box control is exposed
through the control's NameProperty value. Because the Combo Box control is in the content view of the UI
Automation Tree, it is not necessary for the text control to be there. Text controls always have 0 children in the
content view
See Also
Text
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the Thumb Control Type
4/14/2017 2 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the Thumb control type. In UI Automation, a
control type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values, and control
patterns.
Thumb controls provide the functionality that enables a control to be moved (or dragged), such as a scroll bar
button, or resized, such as a window resizing widget. Thumb controls can also be implemented as movable borders
of panes. Note that it does not provide drag-and-drop functionality. Thumb controls can receive mouse focus but
usually not keyboard focus. The control developer must implement the control so that it acts appropriately (can be
dragged or resized).
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the Thumb control type. The UI Automation requirements apply to all thumb controls, whether Windows
Presentation Foundation (WPF), Win32, or Windows Forms.
Thumb controls never appear in Content View because they only exist for being manipulated with a mouse. Their
functionality is exposed though another control pattern, such as Scroll Pattern, Transform Pattern, or RangeValue
Pattern, being supported on the Thumb container.
ClickablePointProperty See notes. Any point within the visible client area
of the Thumb control.
See Also
Thumb
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the TitleBar Control Type
4/14/2017 2 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the TitleBar control type. In UI Automation, a
control type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values and control
patterns.
Title bar controls represent titles or caption bars in a window.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the TitleBar control type. The UI Automation requirements apply to all title bar controls, whether Windows
Presentation Foundation (WPF), Win32, or Windows Forms.
- Menu (0 or 1)
- Button (0 or more)
LabeledByProperty See notes. The title bar control usually does not
have a label.
See Also
TitleBar
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the ToolBar Control Type
4/14/2017 2 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the ToolBar control type. In UI Automation, a
control type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values and control
patterns. Tool bar controls enable end users to activate commands and tools contained within a application.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the ToolBar control type. The UI Automation requirements apply to all tool bar controls, whether Windows
Presentation Foundation (WPF), Win32, or Windows Forms.
ToolBar ToolBar
A tool bar control can contain any type of control within its subtree. They most often contain buttons, combo
boxes, and split buttons.
See Also
ToolBar
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the ToolTip Control Type
4/14/2017 3 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the ToolTip control type. In UI Automation, a
control type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values and control
patterns.
Tool tip controls are pop-up windows that contain text.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the ToolTip control type. The UI Automation requirements apply to all tool tip controls, whether Windows
Presentation Foundation (WPF), Win32, or Windows Forms.
ToolTip ToolTip
- Text (0 or more)
- Image (0 or more)
Tool tip controls appear only in the Content View of the UI Automation tree if they can receive keyboard focus.
Otherwise, all of the tool tip's information is available from the HelpTextProperty on the UI Automation element
that the tool tip is referring to.
Tool tips should appear beneath the control that their information is referring to. Clients must listen for the
ToolTipOpenedEvent to ensure that they consistently obtain information contained in tool tips.
NameProperty See notes. The name of the tool tip control is the
text that is displayed within the tool tip.
See Also
ToolTip
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the Tree Control Type
4/14/2017 4 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the Tree control type. In UI Automation, a control
type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values, and control
patterns.
The Tree control type is used for containers whose contents have relevance as a hierarchy of nodes, as with the
way files and folders are displayed in the left pane of Microsoft Windows Explorer. Each node has the potential to
contain other nodes, called child nodes. Parent nodes, or nodes that contain child nodes, can be displayed as
expanded or collapsed.
The following sections define the required UI Automation tree structure, properties, control patterns, and events for
the Tree control type. The UI Automation requirements apply to all tree controls, whether Windows Presentation
Foundation (WPF), Win32, or Windows Forms.
Tree Tree
See Also
Tree
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the TreeItem Control
Type
4/14/2017 4 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the TreeItem control type. In UI Automation, a
control type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values and control
patterns.
The TreeItem control type represents a node within a tree container. Each node might contain other nodes, called
child nodes. Parent nodes, or nodes that contain child nodes, can be displayed as expanded or collapsed.
The following sections define the required UI Automation tree structure, properties, control patterns, and events
for the TreeItem control type. The UI Automation requirements apply to all tree item controls, whether Windows
Presentation Foundation (WPF), Win32, or Windows Forms.
TreeItem TreeItem
Tree item controls can have zero or more tree item children in the content view of the UI Automation tree. If the
tree item control has functionality beyond what is exposed in the control patterns listed below, then the control
should be based on the Data Item control type.
Collapsed tree items will not display in the control view or content view until they become expanded and visible
(or, can be scrolled into view).
The control view can contain additional details for a control, including an associated image or a button. For
example, an item in an outline view might contain an image as well as a button to expand or collapse the outline.
These detail objects don't appear in the content view because the information is already represented by the parent
tree item. Tree items that are scrolled off the screen will appear in both the control and content views of the UI
Automation tree and should have the IsOffscreenProperty set to true.
Required UI Automation Properties
The following table lists the UI Automation properties whose value or definition is especially relevant to list
controls. For more information on UI Automation properties, see UI Automation Properties for Clients.
ExpandCollapseState Expanded, Collapsed, or Leaf Node Tree items will be leaf nodes when they
are not expanded or collapsed.
See Also
TreeItem
UI Automation Control Types Overview
UI Automation Overview
UI Automation Support for the Window Control Type
4/14/2017 2 min to read Edit Online
NOTE
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes
defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows
Automation API: UI Automation.
This topic provides information about UI Automation support for the Window control type. In UI Automation, a
control type is a set of conditions that a control must meet in order to use the ControlTypeProperty property. The
conditions include specific guidelines for UI Automation tree structure, UI Automation property values, and control
patterns.
The window control consists of the window frame, which contains child objects such as title bar, client, and other
objects.
The UI Automation requirements in the following sections apply to all controls that implement the Window control
type, whether Windows Presentation Foundation (WPF), Win32, or Windows Forms.
Window Window
See Also
Window
UI Automation Control Types Overview
UI Automation Overview
UI Automation Specification and Community Promise
4/14/2017 1 min to read Edit Online
UI Automation provides programmatic access to most user interface (UI) elements on the desktop, enabling
assistive technology products such as screen readers to provide information about the UI to end users and to
manipulate the UI by means other than standard input.
See Also
UI Automation Specification
UI Automation Community Promise