AutomationElement.FindAll(TreeScope, Condition) 方法

定義

傳回滿足指定條件的所有 AutomationElement 物件。

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

指定搜尋範圍之值的位元組合。

condition
Condition

包含符合準則的物件。

傳回

符合指定條件的物件集合。 如果沒有符合的成員,則傳回空白集合。

範例

下列範例示範如何使用 FindAll 在視窗中尋找所有已啟用的按鈕。

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

備註

搜尋的範圍相對於呼叫 方法的專案。 元素會依照樹狀結構中遇到的順序傳回。

在桌面上搜尋最上層視窗時,請務必在 中 scope 指定 Children ,而不是 Descendants 。 透過桌面整個子樹的搜尋可能會逐一查看數千個專案,並導致堆疊溢位。

如果您的用戶端應用程式可能會嘗試在自己的使用者介面中尋找元素,您必須在個別執行緒上發出所有消費者介面自動化呼叫。

適用於

另請參閱