none
Could somebody explain when I pass a control's AutomationID, how the code find the correct control and invoke the supported methods?

    Question

  • Hello All,

    Could somebody explain when I pass a control's AutomationID, how the code find the correct control and invoke the supported methods? (Assume I use UIAutomation technology and write the codes in C#) And what's difference between MSAA and UIAutomation ?


    thanks, eric

    Thursday, November 28, 2013 10:03 AM

All replies

  • Hi Eric,

    In brief, Microsoft's UI Automation Framework represents all applications under the desktop as a visual tree of AutomationElements. You can use the UIA framework to search for items in this tree using conditions such as the one you mentioned, AutomationId. You can then request different patterns, each allowing you to perform various actions on the control. A simple example for finding a control (let's assume it's a button and can be clicked) with the AutomationID being 'Demo' -- and then clicking it -- would be:

    // Create the condition for searching the control
    var condition = new PropertyCondition(AutomationElement.AutomationIdProperty, "Demo");
    // Find the control
    var demoElement = AutomationElement.FindFirst(TreeScope.Descendants, condition);
    // Request an InvokePattern object instance
    var invokePattern = demoElement.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
    // Call the click method on the InvokePattern instance
    invokePattern.Click();
    
    

    As for your last question, MSAA is the legacy technology introduced as far as Windows 95 - UIA replaces it (and contains it for legacy support). 

    Monday, January 06, 2014 10:14 AM
  • Hi Tal, thank you very much for your reply. I think I have to re-organize my questions. Actually, what I really want to know is when I launch an application, how windows know the application is launched and add the application's UI elements(buttons/labels/listboxes...) under the desktop which is the root node of the element tree. And which component/service is managing the element tree?

    thanks, eric

    Monday, January 13, 2014 8:31 AM