Monday, May 31, 2010

Overriding GetRowWithCellText Method

GetRowWithCellText method finds the specified text in a webtable and returns the number of the first row found.
If you want to find all matches in a webtable, then we have to override the GetRowWithCellText method using RegisterUserFunc as below,
RegisterUserFunc "WebTable","GetRowWithCellText","NewGetRowWithCellText"

Function NewGetRowWithCellText(obj,val1,val2,val3)
Dim v_st_returnText
Set objRow=obj.Object.getElementsByTagName("TR")
If val2<>0 Then val2=val2-1
If val3<>0 Then val3=val3-1
For i=val3 to objRow.Length-1
If val1=Trim(objRow(i).getElementsByTagName("TD")(val2).InnerText) Then
If v_st_returnText="" Then
v_st_returnText=Cstr( i+1)
Else
v_st_returnText=Cstr( i+1)+","+v_st_returnText
End If
End If
Next
NewGetRowWithCellText=v_st_returnText
End Function

Msgbox Browser("name:=QTP Codes").Page("title:=QTP Codes").WebTable("index:=0").GetRowWithCellText("Cell3",1,1)

2 comments: