Forum Discussion

kalmangt's avatar
kalmangt
Occasional Contributor
8 years ago

Identify RowIndex of Multiple Values

I have a table with multiple rows and two columns.
ColumnIndex 1 may have duplicate values, and ColumnIndex 2 may have duplicate values, but the combination of ColIndex1+ColIndex2 make a unique value.

Sample Data:

COL1     COL2
A               X
A               Y
B               X
B               Y
C               Z

I need to be able to tell my test to click on a row based on the combination of values in two cells. For example, I want the test to click on a cell RowIndex 4 (which in turn selects the entire row), which represents my unique value of B+Y.

Any suggestions for analyzing two separate cell values or a way to determine rowIndex and then click on that specific row? Would be using JScript to accomplish this.

  • Rough pseudocode, untested, but perhaps this will give you an idea.  Basically, you just traverse the table with a for loop comparing the values of the two columns against the desired values with AND logic (they both must equal the desired value).  If we find the row, return the row index and then use that to determine what cell to click.

    function findRow(myTable, column1Value, column2Value){
        var foundRowIndex = -1;
        var tableRowCount;
    
        for (var i = 0; i < tableRowCount; i++) {
            if ((myTable.Cell(i, 0).contentText === column1Value) && (myTable.Cell(i, 1) === column2Value)) {
                foundRowIndex = i;
                break;
            }
    
        }
        return foundRowIndex;
    }
    
    function myTest(){
        var myRow;
        myRow = findRow(Aliases.myApp.myTable, 'B', 'Y');
        if (myRow != -1){
            Aliases.myApp.myTable.Cell(myRow, 0).Click();
        }
        else {
            Log.Error('Could not find a row with values of B and Y');
        }
    
    }
    
    
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Rough pseudocode, untested, but perhaps this will give you an idea.  Basically, you just traverse the table with a for loop comparing the values of the two columns against the desired values with AND logic (they both must equal the desired value).  If we find the row, return the row index and then use that to determine what cell to click.

    function findRow(myTable, column1Value, column2Value){
        var foundRowIndex = -1;
        var tableRowCount;
    
        for (var i = 0; i < tableRowCount; i++) {
            if ((myTable.Cell(i, 0).contentText === column1Value) && (myTable.Cell(i, 1) === column2Value)) {
                foundRowIndex = i;
                break;
            }
    
        }
        return foundRowIndex;
    }
    
    function myTest(){
        var myRow;
        myRow = findRow(Aliases.myApp.myTable, 'B', 'Y');
        if (myRow != -1){
            Aliases.myApp.myTable.Cell(myRow, 0).Click();
        }
        else {
            Log.Error('Could not find a row with values of B and Y');
        }
    
    }
    
    
    • kalmangt's avatar
      kalmangt
      Occasional Contributor

      Thanks for the prompt reply! This is exactly what I was missing.