我有一个使用DataGrid的WPF应用程序;我正在使用WPF ui自动化API为其编写一些自动化测试。
我所处的位置是,从我的测试中可以找到datagrid,并且我可以使用
GridPattern.GetItem
方法,并通过设置
SelectionItemPattern.Select
. 方法
代码看起来有点像这样:
AutomationElement mainGrid = // find the grid in the window
var columnCount = (int)mainGrid.GetCurrentPropertyValue(GridPattern.ColumnCountProperty);
var mainGridPattern = (GridPattern)mainGrid.GetCurrentPattern(GridPattern.Pattern);
var rowToSelect = 2;
// select just the first cell
var item = mainGridPattern.GetItem(rowToSelect, 0);
var itemPattern = (SelectionItemPattern)item.GetCurrentPattern(SelectionItemPattern.Pattern);
itemPattern.Select();
这似乎是可行的,但它只选择第一个单独的单元格,而不是整个表行(有10列),但我不知道如何选择
取消选择
SelectionItemPattern.AddToSelection()
上
itemPattern
,或相应的
RemoveFromSelection
=> Cannot change cell selection when the SelectionUnit is FullRow.
at MS.Internal.Automation.ElementUtil.Invoke(AutomationPeer peer, DispatcherOperationCallback work, Object arg)
at MS.Internal.Automation.SelectionItemProviderWrapper.AddToSelection()
潜在的根问题似乎是(就我所见),WPF UI自动化API没有网格行的概念,只有单元格。这似乎有点问题,对吗?