Facebook

Course Name Start Date Time Duration Registration Link
No Training Programs Scheduled ClickHere to Contact
Please mail To sudhakar@qtpsudhakar.com to Register for any training

Thursday, February 12, 2009

Working with Webtable Object

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 childobjectchilditem  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 (RowColumnMicClassIndex)
 
Getcelldata method is to retrieve data from a web table cell in web table object.
Syntax:-object.GetCellData (RowColumn) 

22 comments :

  1. Very helpful for understanding webtable

    ReplyDelete
  2. Great, could u plz post some more on webtable

    ReplyDelete
  3. great work it is very helpful

    ReplyDelete
  4. Good Article on WebTable

    ReplyDelete
  5. Hello Sudhakar,
    How 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

    ReplyDelete
  6. using regular expression how to find string ="QTP " present or not

    ReplyDelete
    Replies
    1. getRowWithCellText("QTP") will return the row no. if it is not greater than equals to 1 then the text not exist in webtable

      Delete
  7. Hi Sudhakar,
    Its 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.

    ReplyDelete
  8. thanks sudhakar..
    it get good unterstanding of web table for me..Thnks

    ReplyDelete
  9. Great post sudhakar..really helpful post to get better understanding of web table methods.
    Keep posting..

    ReplyDelete
  10. hi sudhakar how can we edit/insert data in to webtable

    ReplyDelete
  11. Script on WebTable. Good to understand and Helpful.

    ReplyDelete
  12. Thanks Sudhaker.
    your posts are a great learning resource.
    Kudo.. for ur efforts. Keep posting.

    Regards,
    Azhar

    ReplyDelete
  13. Thanks Sudhakar, Very good source for learning WebTable.

    ReplyDelete
  14. hi 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

    ReplyDelete
    Replies
    1. Change in position doesn't impact. Use name of the link to compare all 20 objects.

      Delete
  15. Great explanation regarding Web Table Concepts. Thanks for the article...

    ReplyDelete