UI Automation not finding elements shown in Inspect


  • '

    seems to me that this code should return all the edit controls. However it returns nothing at all. Any idea where up?

      For Each ctrl As AutomationElement In root.FindAll(TreeScope.Descendants, New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit))


    Tuesday, April 29, 2014 8:45 PM

All replies

  • Inspect accesses the automation tree by way of the unmanaged UI Automation accessibility (IUIAutomationElement).

    The code that you are using (AutomationElement) access the automation tree by way of the managed Microsoft Active Accessibility (MSAA) implementation.

    It is this difference that is one potential reason for the difference in objects returned.

    Can you try UISpy on your window and see what objects appear?  Alternatively, change your code to use the IUIAutomationElement instead and it should match the objects that inspect returns.

    Wednesday, April 30, 2014 3:59 PM
  • Here's some great examples on how to utilize the unmanaged UIA API through C# via a COM-wrapper.

    Wednesday, April 30, 2014 4:03 PM