Recently we got some feedback from a customer that they are not able to access some control inside a datagrid cell. Basically they wanted to do some validation on this control’s properties. Coded UI Test uses the UIAutomation’s ControlView TreeWalker to do all UI tree navigation. Hence, if a control is not present in the ControlView, it will be unreachable i.e. neither you can navigate to that control using the CUIT’s control locator, nor can you search for it by providing any combination of properties. The RawView TreeWalker could give some additional set of controls. CUIT excludes them since typically these are non-interesting controls and adds too much of verbosity to the CUIT control tree structure.
Unfortunately, this TreeWalker is not currently configurable to the CUIT user. However, all is not lost. You can still do some limited operations on these “elusive” controls. The following code snippet gets the native AutomationElement from the UITestControl and then uses the RawView tree walker to drill down to a child control (which is otherwise inaccessible in the ControlView tree).
UITechnologyElement cellElement = cellUITestControl.GetProperty(UITestControl.PropertyNames.UITechnologyElement) as UITechnologyElement;
AutomationElement ae = cellElement.NativeElement as AutomationElement;
AutomationElement child = System.Windows.Automation.TreeWalker.RawViewWalker.GetFirstChild(ae);
Note that you need to perform all property validations (or any actions such as using UIA Patterns to do some actions, or navigating further with this raw child control as reference) on the control directly using the UIAutomation APIs. You should not create back a UITestControl out of the ‘child’ AutomationElement above since it will be unreachable during the playback search.