AutomationElement.FindAll(TreeScope, Condition) 方法

定義

傳回滿足指定條件的所有 AutomationElement 物件。Returns all AutomationElement objects that satisfy the specified condition.

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

參數

scope
TreeScope

指定搜尋範圍之值的位元組合。A bitwise combination of values that specifies the scope of the search.

condition
Condition

包含符合準則的物件。The object containing the criteria to match.

傳回

AutomationElementCollection

符合指定條件的物件集合。A collection of objects that satisfies the specified condition. 如果沒有符合的成員,則傳回空白集合。If there are no matches, an empty collection is returned.

範例

下列範例顯示如何使用 FindAll ,在視窗中尋找所有啟用的按鈕。The following example shows how to use FindAll to locate all enabled buttons in a window.

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

備註

搜尋範圍相對於呼叫方法的元素。The scope of the search is relative to the element on which the method is called. 專案會依照在樹狀結構中遇到的順序傳回。Elements are returned in the order in which they were encountered in the tree.

搜尋桌面上的最上層視窗時,請務必指定 Children in scope 、not DescendantsWhen searching for top-level windows on the desktop, be sure to specify Children in scope, not Descendants. 搜尋整個桌面的整個子樹可逐一查看數以千計的專案,並導致堆疊溢位。A search through the entire subtree of the desktop could iterate through thousands of items and lead to a stack overflow.

如果您的用戶端應用程式可能會嘗試在其本身的使用者介面中尋找元素,您必須在個別的執行緒上進行所有的消費者介面自動化呼叫。If your client application might try to find elements in its own user interface, you must make all UI Automation calls on a separate thread.

適用於

另請參閱