Wednesday 7 May 2014

QTP - UFT - How to count the number of columns and numbers of rows in a table

From Interviewer stand point he may provide the applicant with a sample table such as the one shown below and can ask the applicant to find the number of columns and number of rows in table


Slno
Student Name
Student Registered ID
1
John Henkey
R2014010156789
2
Peter Mark
R2014010157892
3
Mary R
R2014010168975


Below is the code that can help you to retrieve the Table row and column count

Code 
Please run the below code in UFT/QTP to see the result

To Get the Row Count
strRowCnt = Browser("name:=UFT Questions.*").Page("title:=UFT Questions.*").WebTable("column names:=Slno;Student Name;Student Registered ID").GetROProperty("rows")

Msgbox strRowCnt
Output is 4

strRowCnt = Browser("name:=UFT Questions.*").Page("title:=UFT Questions.*").WebTable("column names:=Slno;Student Name;Student Registered ID").RowCount

Msgbox strRowCnt
Output is 4



To Get the Column Count
strColCnt = Browser("name:=UFT Questions.*").Page("title:=UFT Questions.*").WebTable("column names:=Slno;Student Name;Student Registered ID").GetROProperty("cols")

Msgbox strColCnt
Output is 3

We may some time require column count of a particular row. In that case this will work, where RowNumber=2 is refereing to the second row of the table

RowNumber = 2
strColCnt = Browser("name:=UFT Questions.*").Page("title:=UFT Questions.*").WebTable("column names:=Slno;Student Name;Student Registered ID").ColumnCount(RowNumber)

Msgbox strColCnt
Output is 3

Regards,
Sreenu Babu

4 comments:

  1. Thanks Sreenu Babu

    ReplyDelete
  2. how get particular column name and particular row

    ReplyDelete
  3. how can yo find the exact location of "Peter Mark". In other words how do i capture the row number and column number where "Peter Mark" is present

    ReplyDelete