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.
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);
a UI automation project at work uses:
List<White.Core.UIItems.WindowItems.Window> windows = WindowFactory.Desktop.DesktopWindows();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With