Seapine Labs
Personal tools

Locating a Cell in a Custom Grid

From Seapine Labs

Jump to: navigation, search

[edit] Custom grids

Many custom grids are identified in the repository as generic controls, making it impossible to reference individual cells as separate controls. You must use low-level commands and key presses to navigate the grid. Before you can navigate the grid, you must locate a cell and place the cursor in the cell. For example, the first cell of the grid is located at the coordinates X=128 and Y=111. Using those coordinates in the LeftMouseDown and LeftMouseUp statements, you can click the first cell of the grid and then use KeyPress statements to tab to the different cells.

In many cases, you can obtain this information from the repository entry for the grid using the Parent Relative Rectangle or Screen Relative Client Rectangle properties.

If you cannot locate coordinates of a given cell, use an OCR checkpoint to retrieve them.

Note: The OCR add-in is sold separately.

The following examples show how to retrieve data from a custom grid and how to locate a specific cell.

[edit] Locating a cell with a specific value

The following example shows a function that returns the Y coordinate of a cell that contains a specific value. The Y coordinate can be passed into other low-level action statements to control the script behavior. The following example uses the DataGridView application that contains a two-column custom grid. The Y coordinate for the top of the first column is 24.

Figure 1: DataGridView application
Figure 1: DataGridView application

The following FindCell function accepts one argument, which is the text you are searching for.

Figure 2: FindCell function
Figure 2: FindCell function

Line 44 creates a variable that indicates whether the search criteria was located. It also controls the loop. It is set equal to False initially. The variable Y stores the Y coordinate of the current cell. Because the top of the grid has a Y coordinate of 41, the Y variable is set to 41. Lines 47 through 59 are a loop that repeats as long as a matching value is not found (FOUND = FALSE) and the script has not reached the end of the grid (Y<353).

Line 51 creates a variable named ‘CURRENT_CELL’ that stores the text in the current cell. Lines 53 through 57 compare the data in the current cell to the search criteria. If the two values match, then the FOUND variable is set to TRUE, the script exits the loop, and returns the value of Y. If the current cell and the search criteria do not match the function adds 22 to the Y variable, which moves the focus to the next row, and repeats the comparison.

If the loop reaches the end of the grid without locating the search criteria, Y is set to 0 (Lines 61 through 63).

The following shows a script that uses the FindCell function that clicks the cell that contains the number 7.

Figure 3: FindCell function in a script
Figure 3: FindCell function in a script

Note: In this example, the FindCell function is stored in a separate script named GridFunctions.

Issue Management Software | Source Code Control Software | Test Case Management | Requirements Management Software