Export (0) Print
Expand All

AutomationElement.FindAll Method

Returns all AutomationElement objects that satisfy the specified condition.

Namespace: System.Windows.Automation
Assembly: UIAutomationClient (in uiautomationclient.dll)

public AutomationElementCollection FindAll (
	TreeScope scope,
	Condition condition
)
public AutomationElementCollection FindAll (
	TreeScope scope, 
	Condition condition
)
public function FindAll (
	scope : TreeScope, 
	condition : Condition
) : AutomationElementCollection
Not applicable.

Parameters

scope

A bitwise combination of values that specifies the scope of the search.

condition

The object containing the criteria to match.

Return Value

A collection of objects that satisfies the specified condition. If there are no matches, an empty collection is returned.

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.

When 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.

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;
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft