Manipulating WebTables in QTP:


WebTable in QTP WebTable Operation in QTP:

A table is a collection of rows or rows and  columns.Each row can have n no. of columns and  each column  can have n no. of rows.First we’ll proceed counting  total number of tables on the page.Then,we’ll collect total no. of rows and consequently total number of columns within a specific row.

Well, we can count the no. of tables as tableObject.Count() similarly we cannot count total number of columns as TableObject.ColumnCount(),coz this is baseless there may be n no. of columns within a row;hence we need to provide the row no. first while proceeding with counting the no. of columns.The syntax is TableObject.ColumnCount(1);here 1 indicates that we gonna count total column from the first row of the table.Again there exist a issue;What if there are more then 1 table on the page? We can overcome this problem with supplementing ordinal identifier to the table.We use Index property.Syntax is TableObject(0).ColumnCount(1).

So,Finally above script will fetch the total number of columns from the first row of the first table.I have tried to show as many operation(single and using loop) on WebTable which are as follows;

'**********************************************
'Purpose:Manipulating WebTables
'Author:QTP Lab:--A touch of madness
'Website:https://automationlab09.wordpress.com
'Last modified:09/05/2009

'****************************************************
SystemUtil.Run "iexplore.exe","example.com"
 Set oDesc = Description.Create()
oDesc("html tag").Value = "TABLE"
Set oChild = Browser("micclass:=Browser").Page("micclass:=Page").ChildObjects(oDesc)
'Counting number of tables on the page
MyTableCount = oChild.Count
Msgbox "We have " & MyTableCount &" tables"

'Counting number of rows on the First table ie.0th table
Total_rows=oChild(0).RowCount
Msgbox "Table has" &Total_rows &"Rows"

'Counting number of column on the First Row of First Table
Total_cols=oChild(0).ColumnCount(1)
Msgbox "This Row has" &Total_cols &"Columns"

'Retrieving datas from 4th row of 1st column on First Table
Datas=oChild(0).GetCellData(4,1)
Msgbox Datas

'Click on the Link on the 4th row of the table
oChild(0).ChildItem(4,1,"Link",0).Click
'Type text on the Textbox on the 1st row of the table
oChild(0).ChildItem(1,1,"WebEdit",0).Set "Qtp Tester"
Set oChild = Nothing
Set oDesc = Nothing
Count the Total number of Tables,rows and columns on the page and retrieve it's content?

Sol:
SystemUtil.Run "iexplore.exe","http://example.com"

Set oDesc = Description.Create()

oDesc("html tag").Value = "TABLE"

Set oChild = Browser("micclass:=Browser").Page("micclass:=Page").ChildObjects(oDesc)

'Counting number of tables on the page

MyTableCount = oChild.Count

Msgbox "We have " & MyTableCount &" tables"

'Counting number of rows on the total table

For i=0 to MyTableCount-1

For Total_rows=1 to oChild(i).RowCount

Total_cols=oChild(i).ColumnCount(Total_rows)

Retrieved_data=oChild(i).GetCellData(Total_rows,Total_cols)

Msgbox "Table" &i &"has" &Total_rows &"Rows"

Msgbox "Table" &i &"has" &Total_cols &"Columns"

Msgbox "Datas:" &Retrieved_data

Next
Next
Set oChild = Nothing
Set oDesc = Nothing

' Retrieving text from table,rows,cols etc..

Set MyCell = Browser("micclass:=browser").Page("micclass:=page").WebTable("name").ChildItem(3, 2, "WebElement", 0)

Msgbox MyCell.GetROProperty("innertext")
Advertisements

3 responses to this post.

  1. Posted by satyaprakash Pani on August 17, 2011 at 2:52 pm

    This is very useful for a qtp learner.
    Thanks

    If any other Script U have, Please send in my mailid

    Reply

  2. Posted by Anonymous on October 8, 2011 at 12:22 pm

    I was exactly looking for this..Thanks for the wonderful article.

    Reply

  3. Posted by Anonymous on April 26, 2012 at 12:55 pm

    i faced lot of trouble for this one…. I really thankful for your best article….

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: