Question

I am trying to find all desktop windows using .NET UIAutomation OR White framework. I tried :

1.)

            AutomationElement rootElement = AutomationElement.RootElement;
            var winCollection = rootElement.FindAll(TreeScope.Subtree, Condition.TrueCondition);

2.)

            Desktop.Instance.Windows();

Both throw ArgumentException. Please let me know if there are other ways to do this...

UPDATE/ANSWER: Desktop.Instance.Windows(); works fine except that it throws exception while debugging the code using VS2010.

Was it helpful?

Solution

Using TreeScope.Children should work if you want to access the immediate child elements of the desktop ::

    AutomationElement rootElement = AutomationElement.RootElement;
    var winCollection = rootElement.FindAll(TreeScope.Children, Condition.TrueCondition);

    foreach (AutomationElement element in winCollection)
        Console.WriteLine(element.Current.Name);

OTHER TIPS

a UI automation project at work uses:

List<White.Core.UIItems.WindowItems.Window> windows = WindowFactory.Desktop.DesktopWindows();

It's impossible by means of the FindAll call. Some types of windows are available only by calling FindWindow. These may be a child window of MMC console, at the time when the main window of mmc is hidden and unavailable to UI Automation. Is there a way to get a thread the window is on, in case the window is not the main window of the application? The answer is to enumerate threads (often, administrative rights are needed) and calculate which is the thread the window of our interest belongs to.

Generally, there seems no way available to enumerate all the windows as it does Spy++. For example, Get-UIAWindow simply calls FindWindow if UI Automation search was fruitless.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top