Share via


AutomationElement.FindAll(TreeScope, Condition) Metodo

Definizione

Restituisce tutti gli oggetti AutomationElement che soddisfano la condizione specificata.

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

Parametri

scope
TreeScope

Combinazione bit per bit di valori che specifica l'ambito della ricerca.

condition
Condition

Oggetto contenente i criteri da soddisfare.

Restituisce

AutomationElementCollection

Raccolta di oggetti che soddisfa la condizione specificata. Se non sono presenti corrispondenze, viene restituita una raccolta vuota.

Esempio

Nell'esempio seguente viene illustrato come usare FindAll per individuare tutti i pulsanti abilitati in una finestra.

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

Commenti

L'ambito della ricerca è relativo all'elemento in cui viene chiamato il metodo. Gli elementi vengono restituiti nell'ordine in cui sono stati rilevati nell'albero.

Quando si cerca una finestra di primo livello sul desktop, assicurarsi di specificare Children in scope, non Descendants. Una ricerca attraverso l'intero sottoalbero del desktop potrebbe scorrere migliaia di elementi e portare a un overflow dello stack.

Se l'applicazione client potrebbe provare a trovare elementi nella propria interfaccia utente, è necessario eseguire tutte le chiamate Automazione interfaccia utente in un thread separato.

Si applica a

Vedi anche