1

Basically I am using UIAutomationClient.Interop.dll for some UI work I am currently doing and I am facing the following issue:

  • I have a UI Element I would like to know its Control Type.
  • UIAutomationClient.Interop.dll exposes the following property: IUIAutomationElement::CurrentControlType property
  • Above property returns an Int that represents the Control Type ID but not a ControlType object.

Question:

  • How could I know what is the ControlType of an UI Element by just knowing its ID? I was not able to find out any other useful information.

NOTE:

I am using the UIAutomationTypes.dll to definte the ControlType object

Any idea?

user3587624
  • 1,427
  • 5
  • 29
  • 60

2 Answers2

1

I use GetCurrentPropertyValue(AutomationElement.ControlTypeProperty) in IronPython. Probably this is what you want. It should return ControlType object. Though I use its string representation .ProgrammaticName.lstrip('ControlType.').strip("'").

Vasily Ryabov
  • 9,386
  • 6
  • 25
  • 78
  • I tried that out and I am getting an exception. Basically what I did was: var currentControlType = root.GetCurrentPropertyValue(root.CurrentControlType); It returned that the value does not fall withing the expected range. – user3587624 Jul 15 '14 at 18:47
  • Okay, it works different in C# and IronPython. There is C# code that works for me: `root.Current.ControlType.ProgrammaticName`. It returns string "ControlType.Pane". So `root.Current.ControlType` represents a ControlType object. It has `Id` property as well. – Vasily Ryabov Jul 16 '14 at 14:52
  • Maybe I am using a different DLL but I cannot call to root.Current.ControlType.ProgrammaticName. The Interop DLL I am using allow me to do root.CurrentControlType that returns a string object and not a ControlType object. Where did you get your DLL from? – user3587624 Jul 16 '14 at 16:29
  • `C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\UIAutomationClient.dll` – Vasily Ryabov Jul 17 '14 at 10:03
0

For those still looking how to do this in 2021 (with IUIAutomationElement). You simply need to use the LookupById() function provided by the System.Windows.Automation.ControlType class.

// 
IUIAutomationElement element;
// ...
// your code to retrieve the element you want
// ...

// the next line fixes a bug in ControlType class, as explained here: https://stackoverflow.com/a/13971182/991782
ControlType.Button.ToString();

var elementControlType = System.Windows.Automation.ControlType.LookupById(element.CurrentControlType);
fvlinden
  • 313
  • 2
  • 6