Partager via


Obtenir les propriétés d'éléments UI Automation

RemarqueRemarque

Cette documentation s'adresse aux développeurs .NET Framework qui veulent utiliser les classes UI Automation managées définies dans l'espace de noms System.Windows.Automation.Pour obtenir les informations les plus récentes sur UI Automation, consultez API Windows Automation : UI Automation (page éventuellement en anglais).

Cette rubrique montre comment récupérer les propriétés d'un élément UI Automation.

Obtenir une valeur de propriété actuelle

  1. Obtenez le AutomationElement dont vous souhaitez obtenir la propriété.

  2. Appelez GetCurrentPropertyValue ou récupérez la structure de propriété Current et obtenez la valeur de l'un de ses membres.

Obtenir une valeur de propriété mise en cache

  1. Obtenez le AutomationElement dont vous souhaitez obtenir la propriété. La propriété doit avoir été spécifiée dans CacheRequest.

  2. Appelez GetCachedPropertyValue ou récupérez la structure de propriété Cached et obtenez la valeur de l'un de ses membres.

Exemple

L'exemple suivant présente différentes façons de récupérer les propriétés actuelles d'un 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;
}

Voir aussi

Tâches

Utiliser la mise en cache dans UI Automation

Concepts

Propriétés UI Automation pour les clients

Mise en cache dans les clients UI Automation