Επεξεργασία

Κοινή χρήση μέσω


AutomationElement.AutomationIdProperty Field

Definition

Identifies the AutomationId property, which is used to identify elements.

public: static initonly System::Windows::Automation::AutomationProperty ^ AutomationIdProperty;
public static readonly System.Windows.Automation.AutomationProperty AutomationIdProperty;
 staticval mutable AutomationIdProperty : System.Windows.Automation.AutomationProperty
Public Shared ReadOnly AutomationIdProperty As AutomationProperty 

Field Value

Examples

The following example retrieves the current value of the property. The default value is returned if the element does not provide one.

string autoId =
    autoElement.GetCurrentPropertyValue(AutomationElement.AutomationIdProperty) as string;
Dim autoId As String = _
    CStr(autoElement.GetCurrentPropertyValue(AutomationElement.AutomationIdProperty))

The following example retrieves the current value of the property, but specifies that if the element itself does not provide a value for the property, NotSupported is to be returned instead of a default value.

string autoIdString;
object autoIdNoDefault =
    autoElement.GetCurrentPropertyValue(AutomationElement.AutomationIdProperty, true);
if (autoIdNoDefault == AutomationElement.NotSupported)
{
    // TODO Handle the case where you do not wish to proceed using the default value.
}
else
{
    autoIdString = autoIdNoDefault as string;
}
Dim autoIdString As String
Dim autoIdNoDefault As Object = autoElement.GetCurrentPropertyValue(AutomationElement.AutomationIdProperty, True)
If autoIdNoDefault Is AutomationElement.NotSupported Then
    ' TODO Handle the case where you do not wish to proceed using the default value.
Else
    autoIdString = CStr(autoIdNoDefault)
End If

Remarks

This identifier is used by UI Automation client applications. UI Automation providers should use the equivalent identifier in AutomationElementIdentifiers.

This property can also be retrieved from the Current or Cached properties.

Return values of the property are of type String. The default value for the property is an empty string.

When it is available the AutomationIdProperty of an element is expected to always be the same in any instance of the application regardless of the local language. The value should be unique among sibling elements but not necessarily unique across the entire desktop. For example, multiple instances of an application, or multiple folder views in Microsoft Windows Explorer, may contain elements with the same AutomationIdProperty, such as "SystemMenuBar".

While support of an AutomationId is always recommended for better testability, this property is not mandatory. Where it is supported, an AutomationId is useful for creating test automation scripts that run regardless of UI language. Clients should make no assumptions regarding the AutomationIds exposed by other applications. An AutomationId is not necessarily guaranteed to be stable across different releases or builds of an application.

Instances of user interface (UI) elements are uniquely identified on the desktop by their RuntimeIdProperty properties.

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.

Applies to

See also