Saturday, August 8, 2015

HOW TO WORK WITH DOM IN QTP

HTML DOM(Documnet object model) is language independent model for representing and interacting with objects in html. It defines the structure for HTML and help in traversing through objects in HTML.
This approach would be helpful when QTP is not able to identify the object.

Lets try to explain some methods that are useful in QTP when we work with DOM

1.getelementbyid
2.getelementbyname
3.getelementbytagname

Lets open the google home page and select the html code for the Search button by pressing the F12 Key than you will get the html code.







In the above code search button, tag name is input so , by using this tagname we can perform the click operation on this.

if we use to find the element with the use of tag name it will return all the objects that is having the tagname as input for that we have to use some trick in the program, how let see below code

'Code to click on the Search button of google with the use of tagname

objname ="btnG"
set btnname =  Browser("Google").Page("Google").Object.getElementsByTagName("input")
For each btn in btnname

If (btn.name =objname) Then
btn.click
Print "Button found"
else
Print "Button not found"
End If

Next

2. Similary we can use the getelementbyid and getelementbyname method for DOM

No comments:

Post a Comment