I try to programmatically read some table rows from a Windows application using System.Windows.Automation
in a C# console app.
The rows are inside a table that is inside a dialog. I'm using Windows accessibility insight which can find the row and show me the tree structure.
I'm able to find the table but not the rows. The only children I found under the table is the scrollbar and its buttons.
I've also tried to invoke the scroll to reload the table in case it's been virtualised.
The grid control:
The row:
Code:
static void Main(string[] args)
{
var appWindow = AutomationElement.RootElement.FindFirst(
TreeScope.Children,
new PropertyCondition(AutomationElement.NameProperty, appName));
if (appWindow != null)
{
// Find the dialog
var dialog = appWindow.FindFirst(TreeScope.Descendants,
new PropertyCondition(AutomationElement.NameProperty, "Plotdata - Test"));
if (dialog != null)
{
var tables = dialog.FindAll(TreeScope.Descendants, new
PropertyCondition(AutomationElement.ControlTypeProperty,
ControlType.Table));
if (tables != null)
{
foreach (AutomationElement table in tables)
{
Console.WriteLine(table.Current.Name);
Console.WriteLine(table.Current.ControlType.ProgrammaticName);
AutomationElementCollection rows =
table.FindAll(TreeScope.Descendants,
new PropertyCondition(AutomationElement.ControlTypeProperty,
ControlType.Custom)); //The row is ControlType.Custom. Also
tried common table items types
}
}
}
}
}