UIAutomation stackoverflow exception rootelement.findfirst


  • I am trying to use System.Windows.Automation to automate GUI regression testing. In the constructor of my test object, I launch the application and locate it in the tree with AutomationElement.RootElement.FindFirst, and I limit the scope of the search to children. I getting a stackoverflowexception every time I run my test just to launch the application and locate the form. Any help wold be greatly appreciated. My constructor:

    <!-- language: c# -->
    public GuiTest(string inFormName, string inExecutable, Dictionary<string, ControlTypes> inElements)
        //Start the GUI
        myProcess = Process.Start(inExecutable);
        //We have to give the application time to fire up
        int count = 0;
            //Get the root element of the GUI
            myParentElement = AutomationElement.RootElement.FindFirst
                (TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, inFormName));
        }while(myParentElement == null && count < 50);
        if (myParentElement == null)
            throw new InvalidOperationException("Could not find form " + inFormName);
        //Get the buttons and stuff

    Monday, September 02, 2013 9:46 PM

All replies

  • Assuming you haven't already found a solution, how many children elements are shown off of "Desktop" when you use Inspect.exe (part of the Windows Debugging Tools). The times that I have seen a StackOverflow exception it was usually tracked down to someone attempting to use the RootElement and then search all descendants (or a tree that was extremely large).
    Wednesday, October 30, 2013 10:28 PM