C# 如何在WpfTable中找到具有选定值的WpfCell?
我正在为我公司的WPF应用程序进行Visual Studio 2013编码UI测试。 在该应用程序中,我们有一个来自Telerik的带有RadGridView的掩码,其中包含所有用户的列表。 因为应用程序仍在开发中,所以我想创建泛型方法。 对于带有userlist的掩码,我想调用一个方法,我给它控件、cellId和cellValue。 编码UI可识别以下层次结构: WpfTable-WpfRow-WpfText 此外,我无法看到网格中的所有用户条目,这意味着在搜索时必须向下滚动。 因此,我对以下方法进行了编程:C# 如何在WpfTable中找到具有选定值的WpfCell?,c#,wpf,telerik,coded-ui-tests,C#,Wpf,Telerik,Coded Ui Tests,我正在为我公司的WPF应用程序进行Visual Studio 2013编码UI测试。 在该应用程序中,我们有一个来自Telerik的带有RadGridView的掩码,其中包含所有用户的列表。 因为应用程序仍在开发中,所以我想创建泛型方法。 对于带有userlist的掩码,我想调用一个方法,我给它控件、cellId和cellValue。 编码UI可识别以下层次结构: WpfTable-WpfRow-WpfText 此外,我无法看到网格中的所有用户条目,这意味着在搜索时必须向下滚动。 因此,我对以下
private void SearchRowAndCell(WpfTable table, string cellId, string cellValue)
{
int n = 0;
int maxIndex = table.RowCount;
while (n < maxIndex)
{
var row = new WpfRow(table);
var rowIdForSearch = "Row_" + n;
row.SearchProperties.Add("AutomationId", rowIdForSearch);
UITestControlCollection foundRows = row.FindMatchingControls();
if (foundRows.Count > 0)
{
row = (WpfRow)foundRows[0];
var cell = new WpfCell(row);
var cellIdForSearch = "Cell_" + n + "_" + cellId;
cell.SearchProperties.Add("AutomationId", cellIdForSearch);
UITestControlCollection foundCells = cell.FindMatchingControls();
if (foundCells.Count > 0)
{
cell = (WpfCell)foundCells[0];
var text = new WpfText(cell);
text.SearchProperties.Add("DisplayText", cellValue);
UITestControlCollection foundTexts = text.FindMatchingControls();
if (foundTexts.Count > 0)
{
text = (WpfText)foundTexts[0];
Mouse.DoubleClick(row, new Point(10, 10));
n = maxIndex;
}
else
{
Keyboard.SendKeys(row, "{Down}", ModifierKeys.None);
}
}
}
n++;
}
}
现在我的问题是,我在尝试获取WpfText控件时遇到了一个异常,因为DisplayText不是搜索属性。
当我尝试显示文本的值时,我什么也找不到
我需要哪个搜索属性来查找具有选定值的WpfText
提前谢谢 您可以尝试使用以下方法:
WpfTable t = new WpfTable();
t.FindFirstCellWithValue(cellValue);
“FindFirstCellWithValue”方法是一个wpfTable内置方法我想您可以迭代单元格内容,找到WpfText,然后使用字符串比较:
var cellContents = cell.GetChildren();
if (cellContents == null || cellContents.Count < 0) continue;
foreach (var content in cellContents)
{
WpfText wpfText = content as WpfText;
if (wpfText != null && wpfText.DisplayText.Equals(cellValue, StringComparison.OrdinalIgnoreCase))
{
Mouse.DoubleClick(row, new Point(10, 10));
}
}
我找到了!我需要比较Name属性。但是,难道没有更好的办法吗?请不要发送到的链接。该解决方案根本不起作用。看起来不错,但只要我要查找的单元格在可见范围内,它就可以工作。通常codedui知道自动滚动Wpf表以查找控件-但如果表不是太大,则可以使用此方法,用try/catch将其包装,并在出现故障时向下滚动表格,直到到达底部或找到所需的单元格。