Winforms 在使用白色UI框架的窗体上找不到DataGrid

Winforms 在使用白色UI框架的窗体上找不到DataGrid,winforms,testing,user-interface,datagrid,white-framework,Winforms,Testing,User Interface,Datagrid,White Framework,几天前,我收到一项要求,要求为我的Windows应用程序(framework 2.0)创建自动化UI测试用例 我决定使用白色作为测试UI框架。现在一切都很好,除了我似乎找不到使用白色框架显示3条记录的DataGrid控件(注意:这不是DataGridView) 我已经使用了VisualUI验证应用程序来验证DataGrid是否确实在表单上,并且它是UI项类型“表”,并且我确实使用了正确的AutomationId作为控件,但仍然不走运 如前所述,我可以找到表单上除DataGrid之外的所有控件。我

几天前,我收到一项要求,要求为我的Windows应用程序(framework 2.0)创建自动化UI测试用例

我决定使用白色
作为测试UI框架。现在一切都很好,除了我似乎找不到使用白色框架显示3条记录的DataGrid控件(注意:这不是DataGridView)

我已经使用了VisualUI验证应用程序来验证DataGrid是否确实在表单上,并且它是UI项类型“表”,并且我确实使用了正确的AutomationId作为控件,但仍然不走运

如前所述,我可以找到表单上除DataGrid之外的所有控件。我做错什么了吗?或者是white根本不支持DataGrid

任何帮助都会很好。谢谢


Bobby最后不得不升级我的应用程序以使用DataGridView控件,而不是使用DataGrid。这似乎解决了问题,因为White似乎不支持DataGrid

我需要从White访问DataGrid,还没有弄明白为什么White不能工作(我有源代码,如果我有时间并深入研究的话),但是,我已经编写了一些基本代码来将网格数据提取到数组中。谢天谢地,白色框架提供了对AutomationElement的访问

下面的代码未优化。。。它是在林帕德组装的

// The first few lines use White
var application = Application.Attach("AppName");
var window = application.GetWindow("The Window Title");
var datagrid = window.Get<White.Core.UIItems.TableItems.Table>("dataGridAutomationId").AutomationElement;

// Now it's using UI Automation
var headerLine = datagrid.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Header));
var cacheRequest = new CacheRequest { AutomationElementMode = AutomationElementMode.Full, TreeScope = TreeScope.Children };
cacheRequest.Add(AutomationElement.NameProperty);
cacheRequest.Add(ValuePattern.Pattern);
cacheRequest.Push();
var gridLines = datagrid.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom));
cacheRequest.Pop();

Console.WriteLine (headerLine.Count + " columns");
Console.WriteLine (gridLines.Count + " rows");

var gridData = new string[headerLine.Count, gridLines.Count];

var headerIndex = 0;
foreach (AutomationElement header in headerLine)
{
  gridData[headerIndex++, 0] = header.Current.Name;
}

var rowIndex = 1;
foreach (AutomationElement row in gridLines)
{
  foreach (AutomationElement col in row.CachedChildren)
  {
    // Marry up data with headers (for some reason the orders were different
    // when viewing in something like UISpy so this makes sure it's correct
    headerIndex = 0;
    for (headerIndex = 0; headerIndex < headerLine.Count; headerIndex++)
    {
      if (gridData[headerIndex, 0] == col.Cached.Name)
        break;
    }

    gridData[headerIndex, rowIndex] = (col.GetCachedPattern(ValuePattern.Pattern) as ValuePattern).Current.Value;
  }
  rowIndex++;
}
//前几行使用白色
var application=application.Attach(“AppName”);
var window=application.GetWindow(“窗口标题”);
var datagrid=window.Get(“dataGridAutomationId”).AutomationElement;
//现在它正在使用UI自动化
var headerLine=datagrid.FindAll(TreeScope.Children,newpropertyCondition(AutomationElement.ControlTypeProperty,ControlType.Header));
var cacheRequest=new cacheRequest{AutomationElementMode=AutomationElementMode.Full,TreeScope=TreeScope.Children};
cacheRequest.Add(AutomationElement.NameProperty);
cacheRequest.Add(ValuePattern.Pattern);
cacheRequest.Push();
var gridLines=datagrid.FindAll(TreeScope.Children,newpropertyCondition(AutomationElement.ControlTypeProperty,ControlType.Custom));
cacheRequest.Pop();
Console.WriteLine(headerLine.Count+列);
Console.WriteLine(gridLines.Count+“行”);
var gridData=新字符串[headerLine.Count,gridLines.Count];
var headerIndex=0;
foreach(车头线中的AutomationElement收割台)
{
gridData[headerIndex++,0]=header.Current.Name;
}
var-rowIndex=1;
foreach(网格线中的AutomationElement行)
{
foreach(行中的AutomationElement列。CachedChildren)
{
//将数据与标题合并(由于某些原因,顺序不同
//在UISpy中查看时,请确保它是正确的
headerIndex=0;
对于(headerIndex=0;headerIndex
我不确定您是否遇到了与我完全相同的问题,因为我没有足够的代码,但我在一个WPF应用程序中遇到了同样的问题,我试图访问一个DataGrid,它实际上是作为一个GridView项编写的,位于ListView中

我的问题的解决方案是告诉White获取一个ListView项(即TestStack.White.UIItems.ListView)而不是一个表,然后一切正常