I am manipulating an old program using UIAutomation. The issue I have involves pressing a button usingInvokePattern
.
After pressing a button that opens up an explorer window and getting the AutomationElement for the window, I get the AutomationELement for an "Open" button, actually a SplitButton. I can find the element easily, but it comes up as a Pane control
rather than a SplitButton Control. However, if I insert a breakpoint before looking for the Button element and manually step through the code in Debug mode, the "Open" button is recognized as a Button.
If I insert a breakpoint after finding the Button Element, the element Name and AutomationID are correct, but ControlType is a Pane instead of a Button. It's bizarre.
The offending code is below: (Net 3.5, VS2010, Win7 x64)
InvokePattern bPattern = (InvokePattern)button.GetCurrentPattern(InvokePattern.Pattern); bPattern.Invoke(); for (int wait = 0; wait < 50; wait++) { if (explorerWindow != null) break; explorerWindow = reportWindow.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Select Report")); Thread.Sleep(200); } explorerOpenButton = explorerWindow.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Open"));