UIAutomation - InvokePattern only works while Debugging - Button is not Recognized as a Button


  • I am manipulating an old program using UIAutomation. The issue I have involves pressing a button using InvokePattern.

    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);
                for (int wait = 0; wait < 50; wait++)
                    if (explorerWindow != null)
                    explorerWindow = reportWindow.FindFirst(TreeScope.Children,
                                                    new PropertyCondition(AutomationElement.NameProperty, "Select Report"));
                explorerOpenButton = explorerWindow.FindFirst(TreeScope.Children,
                                        new PropertyCondition(AutomationElement.NameProperty, "Open"));

    Thursday, September 05, 2013 2:14 AM