WinAppDriver icon indicating copy to clipboard operation
WinAppDriver copied to clipboard

How to access/select data item in a data grid

Open KiranBehara opened this issue 7 years ago • 14 comments

I have a data grid with data items inside it. Data item is having values with hyper link in 1st column. How to select any row/data item in the grid and perform click action on it.

KiranBehara avatar Mar 25 '19 14:03 KiranBehara

how to save the return value from below method ?

gridPattern.GetItem(1, 1).GetClickablePoint();

i think we can perform click event on the return value from the above line of code.

KiranBehara avatar Mar 26 '19 13:03 KiranBehara

You can try something like the following: var pt = gridPattern.GetItem(1, 1).GetClickablePoint(); session.Mouse.MouseMove(null, pt.X, pt.Y); session.Mouse.ContextClick(null);

JunlinZhu avatar Mar 26 '19 22:03 JunlinZhu

MouseMove() method is accepting coordinates in integer.

var pt0 = gridPattern.GetItem(13, 1).GetClickablePoint(); session.Mouse.MouseMove(null,(int)pt0.X, (int)pt0.Y); session.Mouse.ContextClick(null);

Click is happening but not on the cell, out of the application click is happening mostly on the task bar. I tried hard coding the coordinates of the cell(which is having a hyperlink) but still it clicking on task bar.

KiranBehara avatar Mar 27 '19 12:03 KiranBehara

Try reset cursor position by calling MouseMove with (-pt0.X, -pt0.Y) after Click(null): var pt0 = gridPattern.GetItem(13, 1).GetClickablePoint(); session.Mouse.MouseMove(null,(int)pt0.X, (int)pt0.Y); session.Mouse.Click(null); session.Mouse.MouseMove(null,(int)-pt0.X, (int)-pt0.Y);

JunlinZhu avatar Mar 27 '19 18:03 JunlinZhu

Thanks. It is clicking the complete row/data item in the grid, but i want the cell needs to be clicked. Please see the attached screen shot for more details. It selected/clicked the row/data item only. 636 WAP

KiranBehara avatar Mar 29 '19 12:03 KiranBehara

The link you want to click is on left side of the cell, but pt0 is at cell center. You can move the click point to where the link is by adding an offset to pt0.X like: pt0.X = pt0.X - CellWidth/2 + 10;
CellWidth is width of gridPattern.GetItem(13, 1) 10 is an offset from left edge of the cell

JunlinZhu avatar Mar 29 '19 15:03 JunlinZhu

How to find the width? Is there are default property available ?

KiranBehara avatar Apr 01 '19 11:04 KiranBehara

Let me know if the following works:

var pt0 = gridPattern.GetItem(13, 1).GetClickablePoint(); var cellWidth = gridPattern.GetItem(13, 1).Current.BoundingRectangle.Width; session.Mouse.MouseMove(null, (int)(pt0.X - cellWidth/2) + 10, (int)pt0.Y); session.Mouse.Click(null); session.Mouse.MouseMove(null, (int)(pt0.X - cellWidth/2) + 10, (int)-pt0.Y);

JunlinZhu avatar Apr 01 '19 15:04 JunlinZhu

Thanks this is working(for 2 columns) but i tried the same for a data panel with more columns(4,5,6) by replacing cellWidth/2 to cellWidth/gridPattern.Current.ColumnCount It is working for few panels and for few it is just selecting/clicking the data item again.

KiranBehara avatar Apr 02 '19 09:04 KiranBehara

Did you try fetching the children of the cell in which your link is present?

naeemakram avatar Apr 06 '19 19:04 naeemakram

Did you try fetching the children of the cell in which your link is present?

How to access/ navigate(through) the children elements ?

KiranBehara avatar Apr 09 '19 13:04 KiranBehara

I tried and it doesn't work for grid cells. Here's what I did:

var allCells = ratesGrid.FindElementsByTagName("DataItem");
Debug.WriteLine($"Grid cells count: {allCells.Count}");
foreach (OpenQA.Selenium.Appium.AppiumWebElement v in allCells)
{
v.FindElementByLinkText("xyz").Click();
}

naeemakram avatar Apr 10 '19 05:04 naeemakram

KiranBehara: About clicking on cell link, cellWidth/2 should be used regardless column count.

  1. GetClickablePoint() is at cell center, so if your link is on cell's left side, you will miss,
  2. (pt0.X - cellWidth/2) moves the cursor to cell's left edge
  3. (pt0.X - cellWidth/2) + 10 moves cursor to 10 pixel from the left edge where link is

JunlinZhu avatar Apr 10 '19 16:04 JunlinZhu

Hi @KiranBehara @JunlinZhu I am struggling with the same issue. In a grid view, I have a check box in one of the cells that I want to click. So, I am getting the x,y center coordinates for that cell and clicking that but yes, as soon as I do the click operation, the application goes to the background, the click happens somewhere on the desktop or may be the taskbar. A month ago, this piece of code was working for me and suddenly it's not. Could you please help here.

shilpamalhotra-git avatar Oct 12 '21 10:10 shilpamalhotra-git