0
votes

I want to automate a .NET WinForm appliacation using Teststack White and System.Windows.Automation in c#.

There are at a time several opened windows under MdiClient, I want to get the list of all the sub-windows opened under MdiClient.

I try:

 var window = application.GetWindows().Find(obj => obj.Title.StartsWith("Helios Green"));
 window.Focus(DisplayState.Maximized);

 AutomationElementCollection allChildren = 
      window.AutomationElement.FindAll(TreeScope.Children, 
      new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window));

But this returns empty collection, since the MdiChlidren Windows are not directly children of the main Window, but there is a MdiClient Class Name =WindowsForms10.MDICLIENT.app.0.33c0d9d in between, as seen in Inspect.

How to get the list of all opened MDI sub-windows?

1

1 Answers

0
votes

I was able to workaround like this:

AutomationElementCollection allChildren =
      window.AutomationElement.FindAll(TreeScope.Children, 
      new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Pane));
AutomationElementCollection subwindows = 
      allChildren[0].FindAll(TreeScope.Children, 
      new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window));

The MDIClient is the first Pane within the main Window.