0
非常簡單,試圖獲取某個行中每個單元格中的數據。 代碼示例(請閱讀評論)從數據網格中檢索單元格內容AutomationUI
//Get Main window
AutomationElement prog = AutomationElement.RootElement.FindFirst(TreeScope.Children,
new PropertyCondition(AutomationElement.NameProperty, mainTitle));
//Get data grid
var datagrid = prog.FindFirst(TreeScope.Children,
new PropertyCondition(AutomationElement.AutomationIdProperty, "AccountGrid"));
//get rows (returns the correct value)
var rows = datagrid.FindAll(TreeScope.Descendants,
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.DataItem));
foreach (AutomationElement row in rows)
{
//Is NOT null and returns 5, as the number of cells in each row
var findRow = row.FindAll(TreeScope.Children,
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom));
Console.WriteLine("Is findrow null ?: " + (findRow == null) + "cell count: " + findRow.Count);
for (int i = 0; i < findRow.Count -1; i++)
{
//cache request
var cacheRequest = new CacheRequest
{
AutomationElementMode = AutomationElementMode.None,
TreeFilter = Automation.RawViewCondition
};
cacheRequest.Add(AutomationElement.NameProperty);
cacheRequest.Add(AutomationElement.AutomationIdProperty);
cacheRequest.Push();
//Could be a problem with the propertyname?
var cellText = findRow[i].FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "Profile"));
//RETURNS NULL!
Console.WriteLine("Is cellText null? " + (cellText == null));
cacheRequest.Pop();
Console.WriteLine(cellText.Cached.Name);
}
}
基本上就像你看到的,我可以輕鬆地獲得行的量,細胞的每一行中的量,但是當它涉及檢索單元中的數據,則返回null 。它可能是一個緩存問題?
(對不起,我的格式)