Wednesday, February 17, 2010

Accessing Web Objects Using DOM Methods

ElementFromPoint Method
x=Browser("name:=Google").Page("title:=Google").WebEdit("name:=q").GetROProperty("x")
y=Browser("name:=Google").Page("title:=Google").WebEdit("name:=q").GetROProperty("y")
Browser("name:=Google").Page("title:=Google").Object.elementFromPoint(x,y).Value="QTP" 'Sets value in web edit using coordinates

GetElementsByTagName Method
Set obj= Browser("name:=Google").Page("title:=Google").Object.getElementsByTagName("INPUT")
inCount=obj.Length-1
For i=0 to inCount
If obj(i).Name="q" and obj(i).Type="text" Then
Browser("name:=Google").Page("title:=Google").Object.getElementsByTagName("INPUT")(i).Value="QTP" 'Sets value in web edit using tag name.
End If
Next

GetElementsByName Method
Set obj= Browser("name:=Google").Page("title:=Google").Object.getElementsByTagName("INPUT")
inCount=obj.Length-1
For i=0 to inCount
If obj(i).Name="q" and obj(i).Type="text" Then
Browser("name:=Google").Page("title:=Google").Object.getElementsByName(obj(i).Name)(0).Value="QTP" 'Sets value in web edit using element's name.
End If
Next

GetElementByID Method
Browser("name:=Google").Page("title:=Google").Object.getElementByID("XXXX").Value="QTP" 'Sets value in web edit using element's ID

Verifying Child Object Existence Using Contains Method
Set objWebEdit=Browser("name:=Google").Page("title:=Google").WebEdit("name:=q").Object
msgbox Browser("name:=Google").Page("title:=Google").webTable("index:=0").Object.contains(objWebEdit)'If the webtable contains the specified child object, then Contains method will return True.

2 comments:

  1. can any1 tel me the code for accessing all the objects present in an application or object repository without accessing the QTP?

    ReplyDelete
  2. Excellent work done... Right time it is being used for me.

    ReplyDelete