We have an old legacy application we need to automate.
It uses MDI Windows.
We're using UIAutomation and I can succesfully get the appropriate AutomationElement for each MDI Child window.
What I cannot do is bring that element into focus.
Here is some example code that I tried, that fails:
var desktop = AutomationElement.RootElement;
var dolphin = desktop.FindFirst(TreeScope.Children,
new PropertyCondition(AutomationElement.NameProperty,
"Dolphin for Windows",
PropertyConditionFlags.IgnoreCase));
dolphin.SetFocus();
var workspace = dolphin.FindFirst(TreeScope.Children,
new PropertyCondition(AutomationElement.NameProperty,
"Workspace",
PropertyConditionFlags.None));
var childWindow = workspace.FindFirst(TreeScope.Children, new
PropertyCondition(AutomationElement.NameProperty, "Sharp "));
childWindow.SetFocus();
The last line in this code fails with System.InvalidOperationException
Experimenting, I tried finding a control on the childWindow, and calling SetFocus on it. It DID correctly set the focus on the right control, but it did not bring the MDI window to the foreground.
Any ideas?