AutomationElement.FindAll(TreeScope, Condition) Método

Definição

Devolve todos os AutomationElement objetos que satisfazem a 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 especifica o âmbito da pesquisa.

condition
Condition

O objeto que contém os critérios para corresponder.

Devoluções

Uma coleção de objetos que satisfaz a condição especificada. Se não houver correspondências, uma coleção vazia é devolvida.

Exemplos

O exemplo seguinte mostra como usar FindAll para localizar todos os botões ativados numa 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

Observações

O âmbito da pesquisa é relativo ao elemento em que o método é chamado. Os elementos são devolvidos pela ordem em que foram encontrados na árvore.

Ao procurar janelas de topo no ambiente de trabalho, certifique-se de especificar Children em scope, não Descendants. Uma pesquisa por toda a subárvore do ambiente de trabalho pode iterar por milhares de itens e levar a um excesso de pilhas.

Se a sua aplicação cliente tentar encontrar elementos na sua própria interface de utilizador, deve fazer todas as chamadas de Automatização da Interface de Utilizador numa thread separada.

Aplica-se a

Ver também