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 valu...
  • tristaanogre's avatar
    8 years ago

    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');
        }
    
    }