Forum Discussion

sumith_kmenon's avatar
sumith_kmenon
Occasional Contributor
11 years ago

How to get the Column names of a table

Hi,



Identified a table in a web application . But no properties under that object shows column values.



Regards

SUMITH

3 Replies

  • Here is some code that I use - you might find it useful - it finds the column index of a named column assuming the heading is in the top row - it will need some tweaking to do exactly what you want (I am using JScript and have defined some constants etc):




    //looks in the top row for the heading provided and returns the column index (zero based)


    function findColumnHeading(name, table) {


      table.WaitProperty("Exists", true, MEDIUM_LENGTH_TIMEOUT);


      


      table.WaitProperty("VisibleOnScreen", true, MEDIUM_LENGTH_TIMEOUT);


      var numColumns = table.ColumnCount;


      for (var i = 0; i < numColumns; i++) {


        if (table.Cell(0, i).contentText == name) {


          return i;


        }


      }


    }

  • chrisb's avatar
    chrisb
    Regular Contributor
    As Jorge suggested, use the object spy and examine all the properties of the table cells. Examine the table cell with object spy and use the search feature to look for 'RowIndex' and 'ColumnIndex'. I'm taking a guess as what type of app you are testing but you might find these properties.