我真的很难找到wpf细胞控制。我试图将鼠标点击按钮记录到单元格中。我正在使用Coded UI测试构建器。层次结构(ListView (table) -> DataItem (row) -> cell -> Button)
和搜索属性对我来说没问题。但播放失败了。
我也试图手动编码,但仍无法找到细胞控制。
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();
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'来搜索单元格控件,请执行 必须将row指定为容器元素或添加' 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);
但我还是没有运气。请问有谁可以解释如何找到单元格的搜索控件?
答案 0 :(得分:0)
在ListView'上搜索可能失败了表可能有虚拟儿童。如果被搜索的控件是' ListView'的后代。表然后将其包括为父容器可以解决问题。'
在标签中搜索控件时,我偶然发现了几次。为了解决这个问题,我将控件的变量声明与UIMap中控件的位置进行了比较。如果层次结构不同,我将控件Container设置为匹配Map中的内容
答案 1 :(得分:0)
UITestControl WindowControlTillHandle - 是具有WindowHandle的Control 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);
}