Wpf controls 如何使用编码的UI查找单元格控件
我真的很难找到wpf细胞控制。我试着将鼠标点击按钮记录到单元格中。我正在使用编码的UI测试生成器。层次结构ListView表->数据项行->单元格->按钮和搜索属性对我来说看起来不错。但是播放失败了 我也试着手工编码,但仍然找不到单元格控件Wpf controls 如何使用编码的UI查找单元格控件,wpf-controls,coded-ui-tests,Wpf Controls,Coded Ui Tests,我真的很难找到wpf细胞控制。我试着将鼠标点击按钮记录到单元格中。我正在使用编码的UI测试生成器。层次结构ListView表->数据项行->单元格->按钮和搜索属性对我来说看起来不错。但是播放失败了 我也试着手工编码,但仍然找不到单元格控件 WpfTable table = UIMainWindow.UIModelListCustom.UIListViewTable; table.SearchProperties.Add("ControlType", "Table
WpfTable table = UIMainWindow.UIModelListCustom.UIListViewTable;
table.SearchProperties.Add("ControlType", "Table");
table.SearchProperties.Add("AutomationId", "ListView");
table.SearchProperties.Add("ClassName", "Uia.ListView");
table.DrawHighlight();
DrawHighlight方法查找我的表并在其周围绘制一个高光
WpfRow ControlRow = new WpfRow(table);
ControlRow.SearchProperties.Add("ControlType", "DataItem");
ControlRow.SearchProperties.Add("ClassName", "Uia.ListViewItem");
ControlRow.SearchProperties.Add("Instance", "2");
ControlRow.DrawHighlight();
WpfCell cell = new WpfCell(ControlRow);
cell.SearchProperties.Add("ClassName", "Uia.ContentPresenter");
cell.SearchProperties.Add("ControlType", "Cell");
cell.SearchProperties.Add("ColumnIndex", "1");
cell.DrawHighlight();
DrawHighlight方法查找我的行并在其周围绘制高光
WpfRow ControlRow = new WpfRow(table);
ControlRow.SearchProperties.Add("ControlType", "DataItem");
ControlRow.SearchProperties.Add("ClassName", "Uia.ListViewItem");
ControlRow.SearchProperties.Add("Instance", "2");
ControlRow.DrawHighlight();
WpfCell cell = new WpfCell(ControlRow);
cell.SearchProperties.Add("ClassName", "Uia.ContentPresenter");
cell.SearchProperties.Add("ControlType", "Cell");
cell.SearchProperties.Add("ColumnIndex", "1");
cell.DrawHighlight();
现在DrawHighlight方法找不到我的单元格,异常显示:
'System.ArgumentException:未将任何行指定为搜索容器
为了控制。要使用“ColumnIndex”搜索单元格控件,请
必须将行指定为容器元素或将“RowIndex”添加到
搜索单元格的属性。参数名称:SearchProperties'
因此,我添加了其他搜索属性:
cell.SearchProperties.Add("RowIndex", "1");
在此之后,我得到了一个新的例外:
'System.ArgumentException:未将任何表指定为搜索容器
为了控制。使用搜索行或单元格控件的步骤
“ColumnIndex”或“RowIndex”或两者兼有,必须将表指定为
容器元素。参数名称:SearchProperties'
在搜索属性之前,我添加了这一行。在这一点上,我真的不确定它是好的
cell.Container = table;
之后仍无法找到单元格控件,出现异常:
'UITestControlNotFoundException:播放找不到
具有给定搜索属性的控件
其他详情:
TechnologyName: 'UIA'
FrameworkId: 'Wpf'
ClassName: 'Uia.ContentPresenter'
ControlType: 'Cell'
ColumnIndex: '1'
RowIndex: '1'
“ListView”表的搜索可能失败,因为它可能有虚拟化的子项。如果正在搜索的控件是“ListView”表的后代,则将其作为父容器可以解决此问题
我还尝试对容器使用不同的语法:
ControlRow.Container = table;
cell.Container = ControlRow;
Plus尝试将单元格定义为:
WpfCell cell = new WpfCell(table);
但我还是没有任何运气。有人能解释一下如何找到手机的搜索控制吗
“ListView”表的搜索可能失败,因为它可能有虚拟化的子项。如果正在搜索的控件是“ListView”表的后代,则将其作为父容器可以解决此问题
在选项卡中搜索控件时,我曾多次遇到这种情况。为了解决这个问题,我将控件的变量声明与控件在UIMap中的位置进行比较。如果层次结构不同,我将控件容器设置为与映射中的内容相匹配UITestControl WindowControlTillHandle-是具有WindowHandle的控件 string TableAutomationIdProperty-是使用UIAVerify获取的表ID属性 您可以在系统中的以下位置找到UIAVerify工具-C:\Program Files x86\Windows Kits\8.1\bin\x64\UIAVerify
public static void ClickTableContentUIATable(UITestControl WindowControlTillHandle, string TableAutomationIdProperty, int rowIndex, int columnIndex)
{
AutomationElement mainWindow = AutomationElement.FromHandle(WindowControlTillHandle.WindowHandle);
Condition condition1 = new System.Windows.Automation.PropertyCondition(AutomationElement.AutomationIdProperty, TableAutomationIdProperty);
Condition condition2 = new System.Windows.Automation.PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "table");
System.Windows.Automation.AndCondition andCondition = new System.Windows.Automation.AndCondition(new Condition[] { condition1, condition2 });
AutomationElement gridContol = mainWindow.FindFirst(TreeScope.Descendants, andCondition);
AutomationElement dataPanel_UIA = gridContol.FindFirst(TreeScope.Children, new System.Windows.Automation.PropertyCondition(AutomationElement.NameProperty, "Data Panel"));
UITestControl dataPanel = UITestControlFactory.FromNativeElement(dataPanel_UIA, "UIA");
TreeWalker treeWalker = TreeWalker.ContentViewWalker;
AutomationElement element = treeWalker.GetFirstChild(dataPanel_UIA);
List<AutomationElement> tableRowCollection = new List<AutomationElement>();
List<string[]> tableContent = new List<string[]>();
Mouse.Click(UITestControlFactory.FromNativeElement(element, "UIA"));
AutomationElement lastElement = treeWalker.GetLastChild(dataPanel_UIA);
AutomationElement prevElement = null;
do
{
prevElement = element;
if (!tableRowCollection.Contains(element))
{
tableRowCollection.Add(element);
if (tableRowCollection.Count - 1 == rowIndex)
{
Mouse.Click(UITestControlFactory.FromNativeElement(element, "UIA").GetChildren()[columnIndex]);
return;
}
}
if (element == treeWalker.GetLastChild(dataPanel_UIA))
{
Keyboard.SendKeys(dataPanel, "{PageDown}");
element = treeWalker.GetFirstChild(dataPanel_UIA);
continue;
}
element = treeWalker.GetNextSibling(prevElement);
} while (prevElement != lastElement);
}