gpt4 book ai didi

coded-ui-tests - 在 WPF DataGrid 中查找控件?使用编码的 UI

转载 作者:行者123 更新时间:2023-12-04 06:37:22 24 4
gpt4 key购买 nike

enter image description here我正在使用编码 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()

最佳答案

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

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

从您的评论中......

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);

我希望以上内容对您有用

关于coded-ui-tests - 在 WPF DataGrid 中查找控件?使用编码的 UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44018432/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com