Thursday, 20 February 2014

How to find the column number for given column name in webtable in QTP?

Below QTP example shows how we can find out the column position/number for the given column name in the webtable using QTP.

Suppose you know the column name as "Quantity", then you can get it's position using below line of code.
Below function will return the position of the given column in the table. If the column is not found in the table, -1 is returned.

print GetColumnNumber(ObjParent.Webtable("mytable"), "Quantity")


Function GetColumnNumber(byval table, byval columnName)


Result = false

intColumnCount = table.ColumnCount(1)
print "row count " & intColumnCount

For j = 1 to intColumnCount
curColumn =table.GetCellData (1, j)
print curColumn

'It is important to remove the extra spaces using trim function to match the column name properly  
If ucase(trim(columnName)) = ucase(trim(curColumn)) Then
GetColumnNumber=j
Exit Function
        end if
next

GetColumnNumber = -1 

End Function


Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts. You can write to me at reply2sagar@gmail.com

No comments:

Post a Comment

Please Leave your reply. We value your feedback and inputs

Best QTP Books

Everything About QTP

Hello Friends,
You can find QTP study material, Multiple choice questions (mcq), QTP question bank, QTP question papers, QTP notes, QTP questionnaire, scenario based QTP interview questions, QTP tutorial and QTP training on this site.

If you are a fresher or experienced QTP professional with (1/2/3/4) years of experience, this blog is just for you.