私は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]