Wednesday 24 September 2014

Web Table in QTP




QTP helps to identify by providing Web table class. WebTable class provides various methods to work on web table. In this post we will look at the Methods and Examples to use them. Webtable class contains various methods which allows to work on tabular structure.Tables inside web pages are implemented without any name or id attributes most of the times. This makes it difficult for Automation engineer to create robust scripts for identifying the Table correctly at run-time. QTP by default uses the “index” ordinal identifier to recognized a WebTable.


Methods:

ChildItem
Returns a test object from the cell by type and index
Ex:
Set ChildItem = Browser("BrowserName").Page("PageName").WebTable("html
tag:=TABLE").ChildItem(2,1,"WebCheckBox",0)
ChildItem.Click

‘we have to pass row number, column number, Object type and Index(optional)
ChildItemCount
Returns the count of objects of a specific type in the specified cell.
Ex:
ChildItemCount=Browser("Browser").Page("Page").WebTable("html
tag:=TABLE").ChildItemCount(2,1,"WebCheckBox")
Msgbox ChildItemCount

ChildObjects
Returns the collecton of Child Objects Contained within the Object.
Ex:
Set ChildObject = Browser("Browser").Page("Page").WebTable("html
tag:=TABLE").ChildObjects
Msgbox ChildObject.Count
 
For i=1 to ChildObject.Count
msgbox i&" "& ChildObject(i).GetRoProperty("name")
Next

RowCount
Returns the number of rows in the table.
RowCount=Browser("Browser").Page("Page").WebTable("html tag:=TABLE").RowCount
Msgbox RowCount

ColumnCount
Returns the number of column in the table.
Ex:
ColumnCount = Browser("Browser").Page("Page").WebTable("html
tag:=TABLE").ColumnCount(2)
Msgbox ColumnCount
Note: we need to pass rownumber to know the column count
GetCellData
Returns the text contained in the specified cell.
Ex:
CellData = Browser("Browser").Page("Page").WebTable("html
tag:=TABLE").GetCellData(1,1)
Msgbox CellData

GetRowWithCellText
Returns the number of the first row found that contains a cell with the specified text.
Ex:
Msgbox Browser("Browser").Page("Page").WebTable("html
tag:=TABLE").GetRowWithCellText("Hello")


Refer the below sample code to work/handle a Web table.

rc =Browser("E-HRIS view employees").page("E-HRIS view employees").webtable("name:= Webtable_edit").Rowcount
 
'Above  rowcount property will return a integer of the total number of rows in web table.
 
msgbox rc
 
cc=Browser("E-HRIS view employees").page("E-HRIS view employees").webtable("name:= Webtable_edit").Columncount
 
msgbox cc
 
Webtable data validation-
 
Refer a below code to check or retrieve a data
 
Dim colref,actref
 
for c=1 to cc
 
if  trim(lcase  ( Browser( "E-HRIS view employees" ).page( "E-HRIS view employees" ).webtable( "name:= Webtable_edit" ).
 
getcellData(1,c)))="designation") then
 
msgbox c
 
End if
 
next

No comments:

Post a Comment