Hi,
I'm writing a UI automation software. I need to select a row in the datagrid and then click on the run button. I tried most of the example codes in the internet and they didn't work for me. For example for selecting a gridview row:
When I write the following code:
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();
}
I receive the error: "Target element cannot receive focus." which is related to the last line.
I also tried the code:
AutomationElement mainGrid =
var mainGridPattern = (GridPattern)mainGrid.GetCurrentPattern(GridPattern.Pattern);
var rowToSelect = 2;
var itemPattern = (SelectionItemPattern)item.GetCurrentPattern(SelectionItemPattern.Pattern);
itemPattern.Select();
but I and I received the error :"Unsupported Pattern".
I should mention that I'm using UI Spy for retrieving the elements properties.
Could you explain me what's wrong and how should I select a row?