Quantcast
Channel: Windows Desktop Development for Accessibility and Automation forum
Viewing all articles
Browse latest Browse all 585

Select a row of datagrid using UI Automation

$
0
0

Hi,

I'm writing a UI automation software for another 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 each time wasn't successful. 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 = // 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();

but I and I received the error :"Unsupported Pattern".

I should mention that I'm using UI Spy for retrieving the elements properties. I have attached a picture of UI Spy showing this datagrid properties.

Could you explain me what's wrong and how should I select a row?





Viewing all articles
Browse latest Browse all 585

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>