HTML normally has many webtable and we can extract a lot of information using webtable methods in QTP. In this post we will discuss various methods by which we can used for webtable object.
For r=1 to intRowCnt
‘’ This will loop through each row and tell count of column in each row.
intColCnt=Browser("Google").Page("title:=.*").WebTable(“name:=TTable").ColumnCount(r)
MsgBox intColCnt
Next
Where r = row number and c = column number
Set objDesc=Description.Create
objDesc("micclass").value=strobjType
set objChild=Browser("Google").Page("title:=.*").WebTable(“name:=TTa").ChildObjects(objDesc)
func_findObjectinaWebTable = objChild.count
End Function
set objChild= Browser("Google").Page("title:=.*").WebTable(“name:=TestTable").object.getElementsbyTagName(strTagName)
func_findObjectinaWebTable = objChild.length
End Function
ob0jChildCnt=Browser("Google").Page("title:=.*").WebTable(“name:=TestTable,"index:=0").ChildItemCount(introw,intcol,strobjType)
If objChildCnt >0
Childitem will return object oftype defined in arguments for childitem
Set ChldItm = Browser("Google").Page("title:=.*").WebTable(“name:=TestTable,"index:=0").ChildItem(introw,intcol,strobjType,0)
If (strobjType = "Link" or strobjType ="WebEdit") Then
ChldItm.Click
ElseIf(stobjType = "WebCheckBox") Then
ChldItm.Set "ON"
End If
End Function
Example 1: Validate if a webtable exist
boolExist = Browser(…).page(…).webtable(…).existExample 2 : To Find number of rows and columns in a web table
intRowCnt=Browser("Google").Page("title:=.*").WebTable(“name:= TTable").RowCountFor r=1 to intRowCnt
‘’ This will loop through each row and tell count of column in each row.
intColCnt=Browser("Google").Page("title:=.*").WebTable(“name:=TTable").ColumnCount(r)
MsgBox intColCnt
Next
Example 3: How to get data in a particular cell in the data table
strData= Browser("Google").Page("title:=.*").WebTable(“name:=TTable").GetCellData(r,c)Where r = row number and c = column number
Example 4: Using childObject method to find objects of a particular type within a webtable
Public Function func_findObjectinaWebTable(strObjType)Set objDesc=Description.Create
objDesc("micclass").value=strobjType
set objChild=Browser("Google").Page("title:=.*").WebTable(“name:=TTa").ChildObjects(objDesc)
func_findObjectinaWebTable = objChild.count
End Function
Example 5: Using HTML DOM to get count of objects in a webtable
Public Function func_findObjectinaWebTable(strTagName)set objChild= Browser("Google").Page("title:=.*").WebTable(“name:=TestTable").object.getElementsbyTagName(strTagName)
func_findObjectinaWebTable = objChild.length
End Function
Example 6: Using ChildItemCount and childItem in webtable to extract information
Public Function func_findObjectinaWebTable(strObjType,introw,intCol)ob0jChildCnt=Browser("Google").Page("title:=.*").WebTable(“name:=TestTable,"index:=0").ChildItemCount(introw,intcol,strobjType)
If objChildCnt >0
Childitem will return object oftype defined in arguments for childitem
Set ChldItm = Browser("Google").Page("title:=.*").WebTable(“name:=TestTable,"index:=0").ChildItem(introw,intcol,strobjType,0)
If (strobjType = "Link" or strobjType ="WebEdit") Then
ChldItm.Click
ElseIf(stobjType = "WebCheckBox") Then
ChldItm.Set "ON"
End If
End Function