Using the below code (for example) I can cast AutomationElement to UITestControl

AutomationElement e = AutomationElement.FromHandle(Window.WindowHandle);
UITestControl u = UITestControlFactory.FromNativeElement(e, "UIA");

But how can I do it other way round i.e. How to cast a UITestControl to AutomationElement?

2 Answers 2


I just came across this myself. You should be able to simply use the following:

AutomationElement ae = u.NativeElement as AutomationElement;

But be careful to reference the correct assembly in your project - I had issues when referencing UIAutomationClient and had to reference UiaComWrapper instead.

AutomationElement ae = u.NativeElement as AutomationElement;

It's works only with WPF control. For Win32 control, NativeElement returns IAccessible com object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.