Showing posts with label DOM methods for QTP. Show all posts
Showing posts with label DOM methods for QTP. Show all posts

Sunday, November 21, 2010

Beware of setting value in webedit using DOM

If you set value in a disabled webedit, QTP will throw the below error.


But do not enter value in webedit using DOM. The problem is: You can set value in web text box even it is disabled.
We have a work around for this.

Set obj=Browser("name:=Google").Page("title:=Google").WebEdit("index:=1").Object
If Not obj.disabled Then
obj.Value ="qtp"
End If
I always use DOM to retrieve text or count no. of objects. I hope this is helpful.

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.

Thursday, December 31, 2009

Browser Control in QTP using DOT Net Factory

Create browser control instance in QTP using DOT Net factory, then you are able to browse any web pages without browsers. Execute the below code,


Set obj = DotNetFactory.CreateInstance("System.Windows.Forms.Form","System.Windows.Forms")
Set objBrwsr = DotNetFactory.CreateInstance("System.Windows.Forms.WebBrowser","System.Windows.Forms")

With objBrwsr
.Width=800
.Height=800
.AllowNavigation=True
.AllowWebBrowserDrop=True
.IsWebBrowserContextMenuEnabled=True
End With

With obj .Controls.Add objBrwsrEnd with
objBrwsr.Navigate("
www.google.com")
obj.showdialog

Set obj =Nothing
Set objBrwsr=Nothing


You will get DOT Net Dialog with browser control as same as below,



Thanks and regards,

Asiq Ahamed

Accessing HTML Properties using QTP

Part-1

Getting URL from HTML form.

------------------------------------------------------------------------------------

If you want to access URL from a form's action, use the below code.
Syntax: Browser().Page().Object.getElementsByTagName("form")(IndexOfTheForm).action
Example: Msgbox Browser("name:=Google").Page("title:=Google").Object.getElementsByTagName("form")(0).action

Throughout this article I have used Google for all my examples.

How to find hyperlink's color of your webpage

------------------------------------------------------------------------------------

Here is the code to find link's color of your webpage.

Example: Msgbox Browser("name:=Google").Page("title:=Google").Object.alinkColor

How to find a textbox's auto-complete property is enabled or not

------------------------------------------------------------------------------------

Use the below code to find whether the textbox's auto-complete property is enabled or not.

Example: Msgbox Browser("name:=Google").Page("title:=Google").Object.getElementsByName("q")(0).autocomplete

Getting default checked property for radio button and checkbox

------------------------------------------------------------------------------------

If you want to know radio button's or checkbox's default checked property in QTP, then use the simple code which I use frequently.

Msgbox Browser("name:=Google").Page("title:=Google").WebRadioGroup("name:=meta").Object.defaultChecked

Or

Msgbox Browser("name:=Google").Page("title:=Google").Object.getElementByID("cty").defaultChecked

Finding host or hostname of the location or URL.

------------------------------------------------------------------------------------

To find host and port number.

Msgbox Browser("name:=Google").Page("title:=Google").Object.getElementsByTagName("A")(0).Host

To find host name.

Msgbox Browser("name:=Google").Page("title:=Google").Object.getElementsByTagName("A")(0).HostName

Find destination URL

------------------------------------------------------------------------------------

The below code to find a destination URL or an anchor point.

Msgbox Browser("name:=Google").Page("title:=Google").Object.getElementsByTagName("A")(0).Href

Part -2 will be published soon

Please refer the below link, if you want to know more about DOM.

http://www.learnqtp.com/document-object-model-qtp-guide/