AutomationElement.FindAll(TreeScope, Condition) Méthode

Définition

Retourne tous les objets AutomationElement qui satisfont la condition spécifiée.

public:
 System::Windows::Automation::AutomationElementCollection ^ FindAll(System::Windows::Automation::TreeScope scope, System::Windows::Automation::Condition ^ condition);
public System.Windows.Automation.AutomationElementCollection FindAll (System.Windows.Automation.TreeScope scope, System.Windows.Automation.Condition condition);
member this.FindAll : System.Windows.Automation.TreeScope * System.Windows.Automation.Condition -> System.Windows.Automation.AutomationElementCollection
Public Function FindAll (scope As TreeScope, condition As Condition) As AutomationElementCollection

Paramètres

scope
TreeScope

Combinaison d'opérations de bits de valeurs qui spécifient la portée de la recherche.

condition
Condition

Objet contenant les critères à satisfaire.

Retours

AutomationElementCollection

Collection d’objets qui satisfait la condition spécifiée. En l'absence de correspondances, une collection vide est retournée.

Exemples

L’exemple suivant montre comment utiliser FindAll pour localiser tous les boutons activés dans une fenêtre.

/// <summary>
/// Finds all enabled buttons in the specified window element.
/// </summary>
/// <param name="elementWindowElement">An application or dialog window.</param>
/// <returns>A collection of elements that meet the conditions.</returns>
AutomationElementCollection FindByMultipleConditions(
    AutomationElement elementWindowElement)
{
    if (elementWindowElement == null)
    {
        throw new ArgumentException();
    }
    Condition conditions = new AndCondition(
      new PropertyCondition(AutomationElement.IsEnabledProperty, true),
      new PropertyCondition(AutomationElement.ControlTypeProperty, 
          ControlType.Button)
      );

    // Find all children that match the specified conditions.
    AutomationElementCollection elementCollection = 
        elementWindowElement.FindAll(TreeScope.Children, conditions);
    return elementCollection;
}
''' <summary>
''' Finds all enabled buttons in the specified window element.
''' </summary>
''' <param name="elementWindowElement">An application or dialog window.</param>
''' <returns>A collection of elements that meet the conditions.</returns>
Function FindByMultipleConditions(ByVal elementWindowElement As AutomationElement) As AutomationElementCollection
    If elementWindowElement Is Nothing Then
        Throw New ArgumentException()
    End If
    Dim conditions As New AndCondition(New PropertyCondition(AutomationElement.IsEnabledProperty, True), New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button))

    ' Find all children that match the specified conditions.
    Dim elementCollection As AutomationElementCollection = elementWindowElement.FindAll(TreeScope.Children, conditions)
    Return elementCollection

End Function 'FindByMultipleConditions

Remarques

L’étendue de la recherche est relative à l’élément sur lequel la méthode est appelée. Les éléments sont retournés dans l’ordre dans lequel ils ont été rencontrés dans l’arborescence.

Lorsque vous recherchez des fenêtres de niveau supérieur sur le bureau, veillez à spécifier Children scopedans , et non Descendants. Une recherche dans l’ensemble de la sous-arborescence du bureau peut itérer à travers des milliers d’éléments et entraîner un dépassement de pile.

Si votre application cliente peut essayer de trouver des éléments dans sa propre interface utilisateur, vous devez effectuer tous les appels UI Automation sur un thread distinct.

S’applique à

Voir aussi