AutomationElement.GetCurrentPropertyValue Method

Definition

Retrieves the current value of the specified property from an AutomationElement.

Overloads

GetCurrentPropertyValue(AutomationProperty)

Retrieves the value of the specified property on this AutomationElement. An appropriate default value for the property type is returned for properties not explicitly supported by the target user interface (UI) element.

GetCurrentPropertyValue(AutomationProperty, Boolean)

Retrieves the value of the specified property on this AutomationElement, optionally ignoring any default property.

Remarks

The value returned by the GetCurrentPropertyValue method is current at the time it is called. The value can subsequently change by other applications interacting with the user interface (UI).

For some forms of UI, this method will incur cross-process performance overhead. Applications can concentrate overhead by caching properties and then retrieving them by using GetCachedPropertyValue.

GetCurrentPropertyValue(AutomationProperty)

Retrieves the value of the specified property on this AutomationElement. An appropriate default value for the property type is returned for properties not explicitly supported by the target user interface (UI) element.

C#
public object GetCurrentPropertyValue(System.Windows.Automation.AutomationProperty property);

Parameters

property
AutomationProperty

The UI Automation property identifier specifying which property to retrieve.

Returns

An object containing the value of the specified property.

Exceptions

The UI for the AutomationElement no longer exists.

Examples

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

C#
// elementList is an AutomationElement.
string helpString =
    elementList.GetCurrentPropertyValue(AutomationElement.HelpTextProperty) as string;

Remarks

The value returned by the GetCurrentPropertyValue method is current at the time it is called. The value can subsequently change by other applications interacting with the UI.

If the UI Automation provider for the element itself supports the property, the value of the property is returned. Otherwise, a default property specified by UI Automation is returned. For information on default properties, see the property identifier fields of AutomationElement, such as AcceleratorKeyProperty.

For some forms of UI, this method will incur cross-process performance overhead. Concentrate overhead by caching properties and then retrieving them by using GetCachedPropertyValue.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

GetCurrentPropertyValue(AutomationProperty, Boolean)

Retrieves the value of the specified property on this AutomationElement, optionally ignoring any default property.

C#
public object GetCurrentPropertyValue(System.Windows.Automation.AutomationProperty property, bool ignoreDefaultValue);

Parameters

property
AutomationProperty

The UI Automation property identifier specifying which property to retrieve.

ignoreDefaultValue
Boolean

A value that specifies whether a default value should be ignored if the specified property is supported.

Returns

An object containing the value of the specified property, or NotSupported if the element does not supply a value and ignoreDefaultValue is true.

Exceptions

The UI for the AutomationElement no longer exists.

Examples

The following example retrieves the current value of the HelpText 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.

C#
// elementList is an AutomationElement.
object help = elementList.GetCurrentPropertyValue(AutomationElement.HelpTextProperty, true);
if (help == AutomationElement.NotSupported)
{
    help = "No help available";
}
string helpText = (string)help;

Remarks

Passing false in ignoreDefaultValue is equivalent to calling AutomationElement.GetCurrentPropertyValue(AutomationProperty).

If the UI Automation provider for the element itself supports the property, the value of the property is returned. Otherwise, if ignoreDefaultValue is false, a default property specified by UI Automation is returned. For information on default properties, see the property identifier fields of AutomationElement, such as AcceleratorKeyProperty.

The value returned by the GetCurrentPropertyValue method is current at the time it is called. The value can subsequently change by other applications interacting with the user interface (UI).

For some forms of UI, this method will incur cross-process performance overhead. Applications can concentrate overhead by caching properties and then retrieving them by using GetCachedPropertyValue.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9