Share via


AutomationElement.FindAll(TreeScope, Condition) Método

Definición

Devuelve todos los objetos AutomationElement que satisfacen la condición 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

Combinación bit a bit de valores que especifica el ámbito de la búsqueda.

condition
Condition

Objeto que contiene los criterios que deben coincidir.

Devoluciones

Colección de objetos que satisface la condición especificada. Si no existe ninguna coincidencia, se devuelve una colección vacía.

Ejemplos

En el ejemplo siguiente se muestra cómo usar FindAll para buscar todos los botones habilitados en una ventana.

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

Comentarios

El ámbito de la búsqueda es relativo al elemento en el que se llama al método . Los elementos se devuelven en el orden en que se encontraron en el árbol.

Al buscar ventanas de nivel superior en el escritorio, asegúrese de especificar Children en scope, no Descendantsen . Una búsqueda a través de todo el subárbol del escritorio podría recorrer en iteración miles de elementos y provocar un desbordamiento de pila.

Si la aplicación cliente podría intentar buscar elementos en su propia interfaz de usuario, debe realizar todas las llamadas Automatización de la interfaz de usuario en un subproceso independiente.

Se aplica a

Consulte también