Compartilhar via


Obter propriedades de elemento da automação de interface do usuário

Observação

Esta documentação destina.Os desenvolvedores do NET Framework que desejam usar o gerenciado UI Automation classes definidas na System.Windows.Automation namespace.As informações mais recentes sobre UI Automation, consulte API de automação do Windows: Automação da interface do usuário.

This topic shows how to retrieve properties of a UI Automation element.

Get a Current Property Value

  1. Obtain the AutomationElement whose property you wish to get.

  2. Call GetCurrentPropertyValue, or retrieve the Current property structure and get the value from one of its members.

Get a Cached Property Value

  1. Obtain the AutomationElement whose property you wish to get. The property must have been specified in the CacheRequest.

  2. Call GetCachedPropertyValue, or retrieve the Cached property structure and get the value from one of its members.

Exemplo

The following example shows various ways to retrieve current properties of an AutomationElement.

Sub PropertyCallsExample(ByVal elementList As AutomationElement)
    ' The following two calls are equivalent.
    Dim name As String = elementList.Current.Name
    name = CStr(elementList.GetCurrentPropertyValue(AutomationElement.NameProperty))

    ' 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)

End Sub 'PropertyCallsExample
void PropertyCallsExample(AutomationElement elementList)
{
    // The following two calls are equivalent.
    string name = elementList.Current.Name;
    name = elementList.GetCurrentPropertyValue(AutomationElement.NameProperty) as string;

    // 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.
    object help = elementList.GetCurrentPropertyValue(AutomationElement.HelpTextProperty, true);
    if (help == AutomationElement.NotSupported)
    {
        help = "No help available";
    }
    string helpText = (string)help;
}

Consulte também

Tarefas

Use Caching in UI Automation

Conceitos

UI Automation Properties for Clients

Cache em clientes de automação de interface do usuário