Share via


AutomationElement.FindAll(TreeScope, Condition) Método

Definição

Retorna todos os objetos AutomationElement que atendem à condição especificada.

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

Parâmetros

scope
TreeScope

Uma combinação bit a bit de valores que especificam o escopo da pesquisa.

condition
Condition

O objeto que contém os critérios para correspondência.

Retornos

AutomationElementCollection

Uma coleção de objetos que atende à condição especificada. Se não houver nenhuma correspondência, uma coleção vazia será retornada.

Exemplos

O exemplo a seguir mostra como usar FindAll para localizar todos os botões habilitados em uma janela.

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

Comentários

O escopo da pesquisa é relativo ao elemento no qual o método é chamado. Os elementos são retornados na ordem em que foram encontrados na árvore.

Ao pesquisar janelas de nível superior na área de trabalho, certifique-se de especificar Children em scope, não Descendants. Uma pesquisa por toda a subárvore da área de trabalho poderia iterar por meio de milhares de itens e levar a um estouro de pilha.

Se o aplicativo cliente tentar encontrar elementos em sua própria interface do usuário, você deverá fazer todas as chamadas Automação da Interface do Usuário em um thread separado.

Aplica-se a

Confira também