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

パラメーター

scope
TreeScope

検索のスコープを指定する、値のビットごとの組み合わせ。A bitwise combination of values that specifies the scope of the search.

condition
Condition

照合する検索条件を格納するオブジェクト。The object containing the criteria to match.

戻り値

指定した条件を満たすオブジェクトのコレクション。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 scopeはなくDescendants、を指定してください。When searching for top-level windows on the desktop, be sure to specify Children in scope, not Descendants. デスクトップのサブツリー全体を検索すると、何千もの項目を反復処理し、stack overflow に陥る可能性があります。A search through the entire subtree of the desktop could iterate through thousands of items and lead to a stack overflow.

クライアントアプリケーションが独自のユーザーインターフェイスで要素を見つけようとする場合は、すべてUI オートメーションUI Automationの呼び出しを個別のスレッドで行う必要があります。If your client application might try to find elements in its own user interface, you must make all UI オートメーションUI Automation calls on a separate thread.

適用対象

こちらもご覧ください