Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding all windows on desktop using UIAutomation .NET

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.

like image 743
user96403 Avatar asked Apr 17 '12 12:04

user96403


2 Answers

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);
like image 198
Bill Agee Avatar answered Nov 04 '22 23:11

Bill Agee


a UI automation project at work uses:

List<White.Core.UIItems.WindowItems.Window> windows = WindowFactory.Desktop.DesktopWindows();
like image 2
olegvs Avatar answered Nov 04 '22 21:11

olegvs