在WPF DataGrid中查找控件?使用编码的UI

Sur*_*har 5 coded-ui-tests

在此输入图像描述我正在使用编码的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");
Run Code Online (Sandbox Code Playgroud)

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

这是我的总代码:

 WpfTable tableGrid = new WpfTable(DashboarWindow);
 tableGrid.SearchProperties.Add(WpfTable.PropertyNames.ClassName, "Uia.DataGrid");  
  tableGrid.Find();
Run Code Online (Sandbox Code Playgroud)

上面的代码用于在表单中查找数据网格.

WpfRow rowGrid = new WpfRow(tableGrid);
rowGrid.SearchProperties.Add(WpfRow.PropertyNames.ClassName, "Uia.DataGridRow");
Run Code Online (Sandbox Code Playgroud)

上面的代码是数据网格的行

 WpfCell celGrid = new WpfCell(rowGrid);
 celGrid.SearchProperties.Add(WpfCell.PropertyNames.ClassName, "Uia.DataGridCell");
Run Code Online (Sandbox Code Playgroud)

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

 WpfToggleButton toglButtonShowall = new WpfToggleButton(celGrid);
      toglButtonShowall.SearchProperties.Add(WpfToggleButton.PropertyNames.AutomationId, "ShowDetails");
      Mouse.Click(toglButtonShowall);
Run Code Online (Sandbox Code Playgroud)

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

 WpfCustom custDetaPre = new WpfCustom(rowGrid);
 custDetaPre.SearchProperties.Add(WpfCustom.PropertyNames.ClassName, "Uia.DataGridDetailsPresenter");
 custDetaPre.DrawHighlight();
Run Code Online (Sandbox Code Playgroud)

从上面的代码,我得到了例外.custDetaPre.Drawhighlight()

Mic*_*ger 2

我相信您会想要指定一个显式的RowColumn索引。\n将行索引添加到 和WpfRowWpfCell并将列索引添加到WpfCell\n从您的屏幕截图来看,您至少无法限定该行,因为您有 2 行。只要一行中没有多个切换按钮,您可能就不需要列索引。

\n\n

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

\n\n

从你的评论中......

\n\n
WpfRow rowGrid = new WpfRow(tableGrid); \nrowGrid.SearchProperties.Add(WpfRow.PropertyNames.RowIndex , "0");\nWpfCell celDeffe = new WpfCell(rowGrid); \ncelDeffe.SearchProperties.Add(WpfCell.PropertyNames.RowIndex\xe2\x80\x8c\xe2\x80\x8b, "0"); \ncelDeffe.SearchProperties.Add(WpfCell.PropertyNames.ColumnIn\xe2\x80\x8c\xe2\x80\x8bdex, "0");\nWpfToggleButton toglButtonShowall = new WpfToggleButton(celGrid);\ntoglButtonShowall.SearchProperties.Add(WpfToggleButton.PropertyNames.AutomationId, "ShowDetails");\nMouse.Click(toglButtonShowall);\n
Run Code Online (Sandbox Code Playgroud)\n\n

我希望以上内容对你有用

\n