1
我在寫一個UI自動化軟件。我需要在數據網格中選擇一行,然後點擊運行按鈕。我在互聯網上嘗試了大部分示例代碼,但它們並不適合我。例如,用於選擇一個gridview行:使用UI自動化選擇一行數據網格
當我寫入以下代碼:
AutomationElement dataGrid = this.mainWindow.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.AutomationIdProperty, "2885"));
if (dataGrid != null)
{
GridPattern pattern = GetGridPattern(dataGrid);
AutomationElement tempElement = pattern.GetItem(1, 1);
tempElement.SetFocus();
}
我收到錯誤:「目標元件不能接收焦點」這與最後一行有關。
我也試過代碼:
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();
,但我和我收到的錯誤:「不支持的模式」。
我應該提到,我正在使用UI Spy檢索元素屬性。
你能解釋我什麼是錯的,應該如何選擇一行? ! [UI間諜] [1]