How to access/select data item in a data grid
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.
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.
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);
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.
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);
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.
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
How to find the width? Is there are default property available ?
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);
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.
Did you try fetching the children of the cell in which your link is present?
Did you try fetching the children of the cell in which your link is present?
How to access/ navigate(through) the children elements ?
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();
}
KiranBehara: About clicking on cell link, cellWidth/2 should be used regardless column count.
- GetClickablePoint() is at cell center, so if your link is on cell's left side, you will miss,
- (pt0.X - cellWidth/2) moves the cursor to cell's left edge
- (pt0.X - cellWidth/2) + 10 moves cursor to 10 pixel from the left edge where link is
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.