How to iterate through a data grid and access the elements/cells
I have a data grid, i would like to iterate through the grid & access the elements/cell values. Few of my cell values have values with hyperlink i would like to click/interact with it so it can take me to another page.
Is there an ID on your grid? It should just be a matter of grabbing the grid and then it's children. This is the method I've used for ListBoxes, so I'd imagine datagrids are similar:
public WindowsElement SomeList => Session.FindElementByAccessibilityId("someListId");
public IReadOnlyCollection
So in the case of a data grid, the second declaration's XPath would probably be something like ".//dataitem/Text"
thanks magnus, but it is not working
Do you have inspect.exe to look at the accessibility properties of the datagrid? Or can you dump out the page source to see what WinAppDriver is finding?
Yes i have inspect.exe, What properties you are looking for from the data grid ?
This is what my code looks like. Inspect tells me the grid is Data Panel and the rows start with Row.
ReadOnlyCollection<AppiumWebElement> gridRows = uiNoteGrid.FindElementByName("Data Panel").FindElementsByXPath("//Custom[starts-with(@Name, 'Row')]");
foreach (AppiumWebElement row in gridRows)
{
ReadOnlyCollection<AppiumWebElement> cells = row.FindElementsByXPath("//DataItem[contains(@Name, 'row')]");
foreach (AppiumWebElement cell in cells)
{
// work with cells here
}
}
Hope that helps.
In my application, I have a form. When I submit the form, the screen navigation occurs, and data grid shows on the screen. The data from the form is added in the data grid. I am attempting to write a test to check if a field in the new row added to the data-grid is the same as the Name that was provided in the form.
I have access to the data-grid window element, but I am having difficulty in figuring out how to get the data grid row attribute value from the data-grid window element. Please help me in figuring out this issue:
I have tried:
WindowsElement dataGrid = Session.FindElementByAccessibilityId(“MyDataGrid”);
ReadOnlyCollection<AppiumWebElement> collection = dataGrid.FindElementsByXPath("//DataItem[last()]");