AutomationElement.RootElement Property

Definition

Gets the root AutomationElement for the current desktop.

C#
public static System.Windows.Automation.AutomationElement RootElement { get; }

Property Value

The root element.

Examples

The following example code retrieves a collection of all the immediate children of the desktop.

C#
AutomationElementCollection desktopChildren =
    AutomationElement.RootElement.FindAll(
    TreeScope.Children, Condition.TrueCondition);

Remarks

You can use the root element as a starting point for finding other elements, using the FindAll and FindFirst methods.

When searching from the root element, be sure to specify Children in the scope of the search, not Descendants. A search through the entire subtree of the desktop could iterate through thousands of items and lead to a stack overflow.

Applies to

Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10