A day with .Net

My day to day experince in .net

White UI to access a Grid – UI Automation

Posted by vivekcek on January 9, 2015

This code can be used to access a grid cells via White UI.
The grid should implement GridPattern and TablePattern.

var application = Application.Attach("Process");
var window = application.GetWindow("Window Title");
var datagrid = window.Get<Table>("GridName").AutomationElement;
var cacheRequest = new CacheRequest { AutomationElementMode = AutomationElementMode.Full, TreeScope = TreeScope.Descendants };
var gridLines = datagrid.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TabItem));
var list = datagrid.GetSupportedPatterns();
var data = (datagrid.GetCurrentPattern(GridPattern.Pattern) as GridPattern).GetItem(1, 1);
var final = (data.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern).Current.Value;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s