What is a web table object?
Tables are one of the primary design tools for HTML documents. Tables allow for greater control over page layout, allowing creation of more visually interesting pages. Tables are also used to set apart sections of documents, such as in sidebars, navigation bars, or framing images and their titles and captions. Tables have literally changed the look of the Web page. Originally, tables let people present data in a column format. Designers quickly figured out ways to improve the layout of their pages using tables.
A Sample Web Table Object
Every web table contains data (text data) and child objects in specified cells. When we are working with descriptive programming using QTP, web table object is very useful to get data or to get object information for further activities.
Retrieving data from web table
'**********************************************************************
rCount=Browser("Yahoo! Mail: The best").Page("Yahoo! Mail: The best").WebTable("Yahoo! ID:").RowCount
For r=1 to rCount
cCount=Browser("Yahoo! Mail: The best").Page("Yahoo! Mail: The best").WebTable("Yahoo! ID:").ColumnCount(r)
For c=1 to cCount
cData=Browser("Yahoo! Mail: The best").Page("Yahoo! Mail: The best").WebTable("Yahoo! ID:").GetCellData(r,c)
msgbox cData
Next
Next
'**********************************************************************
Step1:- Get row count from table
Step2:-Using “For Loop” Get column count for every row.
Using this row number and column number we can able to identify the cells in a table. To get data from a cell we have to provide row and column numbers of a cell.
Step3:-Get cell data from every cell by providing row and column.
Accessing child objects from web table
'**********************************************************************
Set oWebEdit=Description.Create
oWebEdit("micclass").value="WebEdit"
set objList=Browser("Yahoo! Mail: The best").Page("Yahoo! Mail: The best").WebTable("Yahoo! ID:").ChildObjects(oWebEdit)
For objIndex=0 to objlist.count-1
msgbox objlist(objIndex).getroproperty("html id")
Next
'**********************************************************************
This example is to access web table child objects using description object. This is a common method to get child objects from any parent level object. Not like other objects web table object is having a special method to get child items from web table cell without using description object.
Accessing child objects from web table cell
'**********************************************************************
rCount=Browser("Yahoo! Mail: The best").Page("Yahoo! Mail: The best").WebTable("Yahoo! ID:").RowCount
For r=1 to rCount
cCount=Browser("Yahoo! Mail: The best").Page("Yahoo! Mail: The best").WebTable("Yahoo! ID:").ColumnCount(r)
For c=1 to cCount
oCount=Browser("Yahoo! Mail: The best").Page("Yahoo! Mail: The best").WebTable("Yahoo! ID:").ChildItemCount(r,c,"WebEdit")
For obj=0 to oCount-1
set cObject=Browser("Yahoo! Mail: The best").Page("Yahoo! Mail: The best").WebTable("Yahoo! ID:").ChildItem(r,c,"WebEdit",obj)
msgbox cObject.getROproperty("html id")
Next
Next
Next
'**********************************************************************
This example to access child objects from web table cell. This method doesn’t require description object support to access child objects from web table. For this we are using Childitem method.
Difference between childobject, childitem and Getcelldata methods
ChildObjects method is to access total child objects from web table object using description object.
Syntax:- object.ChildObjects ([Description])
ChildItem method is to access child objects from a web table cell in web table object without using description object.
Syntax:-object.ChildItem (Row, Column, MicClass, Index)
Getcelldata method is to retrieve data from a web table cell in web table object.
Syntax:-object.GetCellData (Row, Column)
Very helpful for understanding webtable
ReplyDeleteSudhakar,
DeleteThanks
Divyang
Testing Team
Great, could u plz post some more on webtable
ReplyDeletegreat work it is very helpful
ReplyDeleteVery explanative..
ReplyDeleteGood Article on WebTable
ReplyDeleteHello Sudhakar,
ReplyDeleteHow can we find a exact value from a web table. Don't know how may rows and columns present in table.
Is there a best way to search a value, except looping through each row and column every time.
If we search every cell of a table, it would degrades search performance.
Thanks,
Vikas
using regular expression how to find string ="QTP " present or not
ReplyDeletegetRowWithCellText("QTP") will return the row no. if it is not greater than equals to 1 then the text not exist in webtable
DeleteHi Sudhakar,
ReplyDeleteIts very helpful for testers and learners.
how to get total single row data from webtable.
Example: Webtable contains 5 rows and 6 columns.
I need to get 2 row data of all columns.
Thanks.
thanks sudhakar..
ReplyDeleteit get good unterstanding of web table for me..Thnks
Great post sudhakar..really helpful post to get better understanding of web table methods.
ReplyDeleteKeep posting..
hi sudhakar how can we edit/insert data in to webtable
ReplyDeleteScript on WebTable. Good to understand and Helpful.
ReplyDeleteGreat Job Sudhaker
ReplyDeletethanks sudhaker
ReplyDeleteThanks Sudhaker.
ReplyDeleteyour posts are a great learning resource.
Kudo.. for ur efforts. Keep posting.
Regards,
Azhar
Thanks Sudhakar, Very good source for learning WebTable.
ReplyDeletehi sudhakar, how to automate similar childitem in webtable which is randomly changing their position. suppose there are 20 smiliar link but i need to automate 17 number link but it changing randomly to any position between 1 to 20... so pls reply soon
ReplyDeleteChange in position doesn't impact. Use name of the link to compare all 20 objects.
DeleteGood efrt
ReplyDeleteGreat explanation regarding Web Table Concepts. Thanks for the article...
ReplyDelete