【问题标题】:Finding Controls in WPF DataGrid? Using Coded UI在 WPF DataGrid 中查找控件?使用编码的 UI
【发布时间】:2017-10-16 12:53:31
【问题描述】:

我正在使用编码 UI 自动化 WPF 应用程序,我试图在数据网格中找到无法找到控件的行,当我向开发人员询问控件层次结构时,他们说他们放了另一个数据网格中的数据网格。当我录制无法找到控件的控件时,谁能帮我谢谢。

单击第一个切换按钮后会显示第二行,实际上它不是第二行,在该行中仅添加了数据网格。这是我的代码..

 WpfCustom custDetaPre = new WpfCustom(rowGrid);
      custDetaPre.SearchProperties.Add(WpfCustom.PropertyNames.ClassName, "Uia.DataGridDetailsPresenter");
      //custDetaPre.SearchConfigurations.Add(SearchConfiguration.AlwaysSearch);
      custDetaPre.SearchProperties.Add(WpfCustom.PropertyNames.TechnologyName, "UIA");

当我尝试在上面的自定义控件中记录第二个切换按钮时,在此自定义控件中放置了数据网格。

这是我的总代码:

 WpfTable tableGrid = new WpfTable(DashboarWindow);
 tableGrid.SearchProperties.Add(WpfTable.PropertyNames.ClassName, "Uia.DataGrid");  
  tableGrid.Find();

以上代码用于在表单中查找数据网格。

WpfRow rowGrid = new WpfRow(tableGrid);
rowGrid.SearchProperties.Add(WpfRow.PropertyNames.ClassName, "Uia.DataGridRow");

以上代码是数据网格的行

 WpfCell celGrid = new WpfCell(rowGrid);
 celGrid.SearchProperties.Add(WpfCell.PropertyNames.ClassName, "Uia.DataGridCell");

上面的代码是数据网格中的第一行和第一个单元格

 WpfToggleButton toglButtonShowall = new WpfToggleButton(celGrid);
      toglButtonShowall.SearchProperties.Add(WpfToggleButton.PropertyNames.AutomationId, "ShowDetails");
      Mouse.Click(toglButtonShowall);

上面的代码是第一个切换按钮,当我点击这个(切换)时,第二行将显示,(第二个切换按钮)但这不是第二行,这是行内的另一个数据网格。要找到第二个数据网格,有一个自定义控件,在这个自定义控件中只有第二个网格存在。但我试图找到这个自定义控件我得到了无法找到控件的异常,自定义控件的代码如下所示。

 WpfCustom custDetaPre = new WpfCustom(rowGrid);
 custDetaPre.SearchProperties.Add(WpfCustom.PropertyNames.ClassName, "Uia.DataGridDetailsPresenter");
 custDetaPre.DrawHighlight();

从上面的代码中我得到了异常。 custDetaPre.Drawhighlight()

【问题讨论】:

  • 在数据网格行中包含切换按钮
  • 编码的 UI 无法查看自定义控件,除非该自定义控件包含对 MSAA 或 UIA 的支持。与视力有问题的人使用屏幕阅读器等所需的支持相同。
  • 我附上了我的数据网格的屏幕截图,在第一个切换按钮中我可以访问,但第二个切换按钮无法跟踪。
  • 感谢@Adrian 的回复,它只是自定义控件,但技术名称是 UIA。
  • 当您使用 Coded UI 记录器中的“十字准线”工具查看控件时,它会显示什么?它可以在屏幕上找到最里面的控件吗?它可以在屏幕截图中显示的底部的465 周围画一个框吗?如果它可以在该值上生成一个断言(如果需要,在沙箱项目中)并将相关的代码位复制到您的测试中。如果不能,则自定义控件不支持足够的 MSAA 或 UIA。

标签: coded-ui-tests


【解决方案1】:

我相信您会想要明确指定 RowColumn 索引。 将行索引添加到WpfRowWpfCell,并将列索引添加到WpfCell 从您的屏幕截图来看,由于您有 2 行,因此您至少没有资格获得该行。只要您在一行中没有多个切换按钮,您可能不需要列索引。

如果你在设置搜索参数后调用rowGrid.FindMatchingControls(),你应该返回两个控件

来自你的 cmets....

WpfRow rowGrid = new WpfRow(tableGrid); 
rowGrid.SearchProperties.Add(WpfRow.PropertyNames.RowIndex , "0");
WpfCell celDeffe = new WpfCell(rowGrid); 
celDeffe.SearchProperties.Add(WpfCell.PropertyNames.RowIndex‌​, "0"); 
celDeffe.SearchProperties.Add(WpfCell.PropertyNames.ColumnIn‌​dex, "0");
WpfToggleButton toglButtonShowall = new WpfToggleButton(celGrid);
toglButtonShowall.SearchProperties.Add(WpfToggleButton.PropertyNames.AutomationId, "ShowDetails");
Mouse.Click(toglButtonShowall);

我希望以上内容对你有用

【讨论】:

  • 嗨迈克尔,谢谢你的回复,我会尽力让你知道。
  • WpfTable tableGrid = new WpfTable(DashWindow.DashItemCustom.DashTabList.PIPrismPrismExtensioTabPage); tableGrid.SearchProperties.Add(WpfTable.PropertyNames.ClassName, "Uia.DataGrid"); tableGrid.Find();
  • WpfRow rowGrid = new WpfRow(tableGrid); rowGrid.SearchProperties.Add(WpfRow.PropertyNames.RowIndex , "0");
  • WpfCell celDeffe = new WpfCell(rowGrid); celDeffe.SearchProperties.Add(WpfCell.PropertyNames.RowIndex, "0"); celDeffe.SearchProperties.Add(WpfCell.PropertyNames.ColumnIndex, "0"); var count = celDeffe.FindMatchingControls().Count;
  • 从屏幕截图来看,第二个切换按钮不在第二行,它在不同的数据网格中,我的意思是另一个数据网格中的数据网格,即一个数据网格中的第一个切换按钮和第二个切换在第二个数据网格中的按钮,在第一个数据网格行中。
猜你喜欢
  • 2011-08-01
  • 2015-06-14
  • 2015-02-15
  • 1970-01-01
  • 2014-05-15
  • 2014-07-21
  • 1970-01-01
  • 1970-01-01
  • 2019-12-04
相关资源
最近更新 更多