AutomationElement.FindAll(TreeScope, Condition) Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Returnerar alla AutomationElement objekt som uppfyller det angivna villkoret.
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
Parametrar
- scope
- TreeScope
En bitvis kombination av värden som anger sökomfånget.
- condition
- Condition
Objektet som innehåller villkoret som ska matchas.
Returer
En samling objekt som uppfyller det angivna villkoret. Om det inte finns några matchningar returneras en tom samling.
Exempel
I följande exempel visas hur du använder FindAll för att hitta alla aktiverade knappar i ett fönster.
/// <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
Kommentarer
Sökomfånget är relativt det element som metoden anropas för. Element returneras i den ordning de påträffades i trädet.
När du söker efter fönster på den översta nivån på skrivbordet måste du ange Children i scope, inte Descendants. En sökning genom hela underträdet på skrivbordet kan iterera genom tusentals objekt och leda till ett stackspill.
Om klientprogrammet kan försöka hitta element i sitt eget användargränssnitt måste du göra alla UI Automation anrop i en separat tråd.