WinAppDriver icon indicating copy to clipboard operation
WinAppDriver copied to clipboard

How to iterate through a data grid and access the elements/cells

Open KiranBehara opened this issue 7 years ago • 6 comments

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.

KiranBehara avatar Mar 27 '19 13:03 KiranBehara

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 SomeListItems => SomeList .FindElementsByXPath(".//ListItem/Text");

So in the case of a data grid, the second declaration's XPath would probably be something like ".//dataitem/Text"

PandaMagnus avatar Mar 27 '19 21:03 PandaMagnus

thanks magnus, but it is not working

KiranBehara avatar Mar 29 '19 12:03 KiranBehara

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?

PandaMagnus avatar Apr 02 '19 22:04 PandaMagnus

Yes i have inspect.exe, What properties you are looking for from the data grid ?

KiranBehara avatar Apr 03 '19 09:04 KiranBehara

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.

cgetty12 avatar Dec 06 '19 20:12 cgetty12

AccessibilityInsights 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()]");

snehansh avatar May 18 '20 00:05 snehansh