Coded Ui test extensibility for VB6 Datagrid


  • Objective:

    To automate the windows application created in Visual basic 6.0 using Coded UI test.


    To automate Visual Basic controls, we are using the Automation ID property instead of control name (Coded ui test doesn’t show the value in control Id property for Visual basic controls and for having uniqueness in control identification we are using Automation Id). In this solution we are facing challenges in using automation id for the Data Grid control. For Data grid control we are getting blank value in Automation id and further control is getting identified as “Pane” control type instead of “Table”.

    Solutions Tried:

    1. To enable the automation id property for the VB6 controls we have created an extension package using the classes UITestExtensionPackage and UITechnologyManager (PFA UIAProxy dll having the code for the same) which set the control support level to native for VB6 controls.

    But this approach is not working for the datagrid control because the automation id obtained using this approach is blank. Few observations on this front:

    1. The control type returned for this datagrid is “Pane”
    2. We tried setting support level to control specific support, but no use.
      1. We also tried using the AutomationElement class but here too got the control type as pane.
      2. We have also used FindFirst method of automation element to get the child elements but it returns null value.
      3. We tried GetElementFromNativeElement method to get the correct element but it is also not returning the expected value.


    To get latest UI automation DLL, we installed the latest KB support for Visual studio service Pack1. We are using the Accessibility DLL to find the support level of data grid. Sample code written below is used for this.


         internal enum OBJID : uint


                WINDOW = 0x00000000,

                SYSMENU = 0xFFFFFFFF,

                TITLEBAR = 0xFFFFFFFE,

                MENU = 0xFFFFFFFD,

                CLIENT = 0xFFFFFFFC,

                VSCROLL = 0xFFFFFFFB,

                HSCROLL = 0xFFFFFFFA,

                SIZEGRIP = 0xFFFFFFF9,

                CARET = 0xFFFFFFF8,

                CURSOR = 0xFFFFFFF7,

                ALERT = 0xFFFFFFF6,

                SOUND = 0xFFFFFFF5,


            internal static IAccessible AccessibleObjectFromWindow(IntPtr windowHandle)


                Guid accessibleGuid = typeof(IAccessible).GUID;

                IAccessible accessible = null;

                if (AccessibleObjectFromWindow(windowHandle, (int)OBJID.WINDOW, ref accessibleGuid, ref accessible) != 0)


                    Trace.TraceError("AccessibleObjectFromWindow failed for window handle {0}", windowHandle);


                return accessible;



            internal static extern int AccessibleObjectFromWindow(IntPtr hWnd, int dwObjectID, ref Guid riid, ref IAccessible pAcc);

            public override int GetControlSupportLevel(IntPtr windowHandle)


                int supportLevel = UiaTechnologyManager.GetControlSupportLevel(windowHandle);

                //if (supportLevel > 1)


                    IAccessible accessibleObject = AccessibleObjectFromWindow(windowHandle);

                    MessageBox.Show(accessibleObject.accDescription.ToString ());

                    if (accessibleObject != null && accessibleObject.accDescription.Contains("custom_property_value"))


                        return (int)ControlSupport.ControlSpecificSupport;



                return (int)ControlSupport.NoSupport;


    Can you please confirm our approach/understanding or provide some pointers for the solution.

    Monday, January 28, 2013 8:14 AM

All replies