UIItem Identification: AutomationId & Un-managed code

Nov 24, 2009 at 10:33 PM

I'm new to this so I may ask something trivial.

In the documentation: http://white.codeplex.com/wikipage?title=UIItem%20Identification&referringTitle=Home

Button button = window.Get<Button>("btnOK"); //default search mechanism is by automation id
button = window.Get<Button>(SearchCriteria.ByAutomationId("btnOK")); // same as above

But when I play with the Windows calculator (the "7" button has the AutomationId = 131 and its name is "7") then it is not the same:

// Button button7 = calcWindow.Get<Button>("131"); Does not work because it is not using the AutoId but name

Button button7c = calcWindow.Get<Button>("7"); // That works <font size="2">



Button button7b = calcWindow.Get<Button>(White.Core.UIItems.Finders.SearchCriteria.ByAutomationId("131")); // same as above

Does that mean that for un-managed code the default is to identify controls by text (name in UIA terminology) even if these controls have an automationID?



Nov 29, 2009 at 6:45 AM
>> Does that mean that for un-managed code the default is to identify controls by text (name in UIA terminology) even if these controls have an automationID? Thats true and I have mentioned it in the documentation.
Nov 30, 2009 at 9:50 PM

Thanks, I guess my confusion comes from that with unmanaged code some controls still have an AutomationId. Why is the default based on managed vs. unmanaged instead of controls having AutomationId vs not having AutomationId ?

Dec 2, 2009 at 8:49 PM

Is there any drawback using AutomationId with unmanaged code (when the AutomationId exists) as it seems better than using the text (name in UIA terminology) because it can be localized.

Dec 9, 2009 at 12:45 PM

AutomationId provided for unmanaged code are not really provided by the application code, so they are generally some numbers. But your point about localization is valid. I would wait and see if there more people who complain about the same. Thanks for you input anyway.

Dec 16, 2009 at 9:02 PM

It seems that for unmanaged code the AutomationId is the WindowId which is not a very stable Id and should probably not be used. My application still uses VB6 (I know…) and most of the controls have a VBName which is a good way to identify.


It is possible to use a searchCriteria such as:

  button = window.Get<Button>(SearchCriteria.ByText("OK"));

 But beside AutomationId, Text (name), Type and Index (there is something call framework but I don’t know what it is for) there is no way of using other properties like the VBname

  button = window.Get<Button>(SearchCriteria.ByVBName("btnClose"));


or in a more generic way, defining the property name and value like


  button = window.Get<Button>(SearchCriteria.ByCustomPropertyName(“VBName”, "btnClose"));


and Also support the  generic And


  button = (Button) window.Get(SearchCriteria.ByControlType(ControlType.Button). AndCustomPropertyName(“VBName”, "btnClose"));

Dec 20, 2009 at 1:46 PM

VBName is something which is not visible at the run time of the application. Please launch UISpy or something and see if this property is visible or not.