Powered by: Dharamveer Saxena

Thursday, November 17, 2011

Using DOM in QTP

DOM (Document Object Method) is a method for QTP engineers to access the source of any webpage direct through VB Scripting.

Using the DOM we can find an object on a web page and then can perform any action like click, set values etc.

For example if you need to check total links on a web browser, then you can use the following code:

Set Links = Browser("Google").Page("Google").Object.all.tags("a")
Msgbox "Total links: " & Links.Length


Or you can also use the following code:


Set Links = Browser("Google").Page("Google").Object.Links
Msgbox "Total links: " & Links.Length


Here, Object property of Page object is used where it represents the HTML document in a given browser. This browser contains links and other objects too. Here, I have used Length property to get the number of items in a collection.


----


Using DOM object we can also find the object on the web page by using the methods like GetElementsByTagName, GetElementByID and more and then perform operations on it.

eg.

we can set value in textbox by using the getElementByID method on browser:

Browser("Google").Page("Google").Object.getElementByID("webeditname").Value="Testing"