AutomationElement.FindAll(TreeScope, Condition) Methode

Definition

Gibt alle AutomationElement-Objekte zurück, die die angegebene Bedingung erfüllen.

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

Parameter

scope
TreeScope

Eine bitweise Kombination von Werten, die den Umfang der Suche angibt.

condition
Condition

Das Objekt, das die zu erfüllenden Kriterien enthält.

Gibt zurück

AutomationElementCollection

Eine Auflistung von Objekten, die die angegebene Bedingung erfüllt. Wenn keine Übereinstimmungen vorhanden sind, wird eine leere Auflistung zurückgegeben.

Beispiele

Das folgende Beispiel zeigt, wie Sie FindAll alle aktivierten Schaltflächen in einem Fenster suchen.

/// <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

Hinweise

Der Bereich der Suche ist relativ zum Element, auf dem die Methode aufgerufen wird. Elemente werden in der Reihenfolge zurückgegeben, in der sie in der Struktur aufgetreten sind.

Wenn Sie nach Fenstern auf oberster Ebene auf dem Desktop suchen, achten Sie darauf, in , nicht Descendantsanzugeben Children scope. Eine Suche durch die gesamte Unterstruktur des Desktops könnte durch Tausende von Elementen durchlaufen und zu einem Stapelüberlauf führen.

Wenn Ihre Clientanwendung möglicherweise versucht, Elemente in einer eigenen Benutzeroberfläche zu finden, müssen Sie alle Benutzeroberflächenautomatisierung Aufrufe an einem separaten Thread vornehmen.

Gilt für

Siehe auch