Compartir a través de


Obtener propiedades del elemento de la UI Automation

NotaNota

Esta documentación está dirigida a desarrolladores de .NET Framework que desean usar las clases administradas de UI Automation definidas en el espacio de nombres System.Windows.Automation.Para obtener información actualizada sobre UI Automation, vea Windows Automation API: UI Automation.

En este tema se muestra cómo recuperar propiedades de un elemento de UI Automation.

Obtener un valor de propiedad actual

  1. Obtenga el elemento AutomationElement cuya propiedad desea obtener.

  2. Llame a GetCurrentPropertyValue o recupere la estructura de la propiedad Current y obtenga el valor de uno de sus miembros.

Obtener un valor de propiedad almacenado en memoria caché

  1. Obtenga el elemento AutomationElement cuya propiedad desea obtener. La propiedad debe haberse especificado en CacheRequest.

  2. Llame a GetCachedPropertyValue o recupere la estructura de la propiedad Cached y obtenga el valor de uno de sus miembros.

Ejemplo

En el ejemplo siguiente se muestran varias maneras de recuperar propiedades actuales de un elemento 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;
}

Vea también

Tareas

Utilizar el almacenamiento en caché en la UI Automation

Conceptos

Propiedades de UI Automation para clientes

Almacenar en caché en los clientes de automatización de la interfaz de usuario