Reputation: 55
I am trying to access the folder using UIAutomation but window element is not detecting.
When i checked with UI Spy it shows the element with class name and process ID. The element i am looking is window element and it comes under explorer process. So when i tried with below code it returns 0 elements. I have attached image for reference. Please help me.
Process[] windowFolders = Process.GetProcessesByName("explorer");
foreach (Process proc in windowFolders)
{
Console.WriteLine(proc.GetType());
proc.Refresh();
Console.WriteLine(proc.MainWindowHandle);
if (proc.MainWindowHandle.ToInt32() != 0)
{
AutomationElement windowExplorer = AutomationElement.FromHandle(proc.MainWindowHandle);
AutomationElementCollection ewindows = windowExplorer.FindAll(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.window));
foreach (AutomationElement ewindow in ewindows)
{
Console.WriteLine("Window Name: " + ewindow.Current.Name + " Window class name: " + ewindow.Current.ClassName);
}
}
}
Upvotes: 1
Views: 1312
Reputation: 55
As @Damien_The_Unbeliever suggested i used root element property. With the help of RootElement property found the solution. It is very useful to find elements on current desktop.
Below is the solution which i found my self.
AutomationElementCollection desktopChildren = AutomationElement.RootElement.FindAll(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Windows));
foreach(AutomationElement dChil in desktopChildren)
{
if (dChil.Current.Name.Contains("Chipset Software"))
{
Console.WriteLine($"{MethodBase.GetCurrentMethod()}: Found Chipset_Software Window");
}
}
Thank you so much @Damien_The_Unbeliever.
Upvotes: 2