2017-09-03 1 views
0

매우 간단하며 특정 행의 각 셀에서 데이터를 가져 오려고합니다. 코드 샘플 u는 볼 수데이터 그리드에서 셀 내용 가져 오기 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을 반환 . 캐시 문제 일 수 있습니까? (내 서식 죄송합니다)

답변

0

그래서 그것으로 조금 땜질 후, 나는 실제로 내가 직접 휴대 할 수있는 캐시를 밀어해야하고,하지 않는 것이 발견

try 
{ 
    AutomationElement prog = AutomationElement.RootElement.FindFirst(TreeScope.Children, 
     new PropertyCondition(AutomationElement.NameProperty, "Window Title")); 
    var datagrid = prog.FindFirst(TreeScope.Children, 
     new PropertyCondition(AutomationElement.AutomationIdProperty, "Your grid")); 
    var rows = datagrid.FindAll(TreeScope.Children, 
     new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.DataItem)); 
    foreach (AutomationElement row in rows) 
    { 
     var findRow = row.FindAll(TreeScope.Children, 
      new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom)); 
     Console.WriteLine("==============="); 
     Console.WriteLine(findRow[1].Current.Name); 
    } 

    Console.WriteLine("==============="); 
} 
catch (Exception e) 
{ 
    Console.WriteLine(string.Format("{0}{1}", e.Message, 
     " At Line:" + e.StackTrace.Substring(e.StackTrace.LastIndexOf(' ')))); 
} 
Console.ReadLine(); 

이 각 행의 두 번째 셀을 가져옵니다.

관련 문제