AutomationElement.FindAll(TreeScope, Condition) Metoda

Definicja

Zwraca wszystkie AutomationElement obiekty spełniające określony warunek.

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

Parametry

scope
TreeScope

Bitowa kombinacja wartości, która określa zakres wyszukiwania.

condition
Condition

Obiekt zawierający kryteria, które mają być zgodne.

Zwraca

Kolekcja obiektów, która spełnia określony warunek. Jeśli nie ma dopasowań, zwracana jest pusta kolekcja.

Przykłady

W poniższym przykładzie pokazano, jak użyć polecenia FindAll , aby zlokalizować wszystkie włączone przyciski w oknie.

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

Uwagi

Zakres wyszukiwania jest powiązany z elementem, na którym wywoływana jest metoda. Elementy są zwracane w kolejności, w której napotkano je w drzewie.

Podczas wyszukiwania okien najwyższego poziomu na pulpicie należy określić Children w scopepliku , a nie Descendants. Wyszukiwanie całego poddrzewa pulpitu może iterować tysiące elementów i prowadzić do przepełnienia stosu.

Jeśli aplikacja kliencka może spróbować znaleźć elementy we własnym interfejsie użytkownika, należy wykonać wszystkie automatyzacja interfejsu użytkownika wywołania w osobnym wątku.

Dotyczy

Zobacz też