How to get column index in a webtable using UFT

Suppose that there is a webtable on the page and you have a column name. Now if you want to get the column index in a webtable, you need to go to each column and verify the column name in the webtable using loop. Once you find the expected column then return the index of that column.

We have a ready-to-use 100% working code block to get column index in a webtable using UFT. Here this function will have 2 arguments. One is the webtable object objTable and another is the name of the column strColName.

Example code to get column index in a webtable using UFT
Function get_Column_index(objTable,strColName)
    strColumnNames = objTable.getROProperty("column names")
    arrColumnNames = Split(strColumnNames, ";")
    ul = UBound(arrColumnNames)
    For i = 0 To ul
        tempCol = Trim(UCase(arrColumnNames(i)))
        If StrComp(tempCol,UCase(strColName)) = 0 Then
            get_Column_index = i + 1
            Exit Function
        End If
    reporter.ReportEvent micFail,strColName & " is not present in the table",""
    CaptureScreenshot "Column presence"
End Function

You may also read

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.