What is Document object Model?
Wikipedia defines Document Object Model(DOM) as:
A platform- and language-independent standard object model for representing HTML or XML and related formats.
For QTP’s sake, I would redefine it to make it simpler. DOM is a method for QTP engineers to access the source (IE –> View –> Source) of any webpage direct through VB Scripting.
When can we use DOM?
One of the very important places you can use it is when a QTP web table checkpoint doesn’t show you the desired content in a cell. I mean the content in the cell is in a format that is not supported by the web table checkpoint. Another use can be when you want to access all the HTML tags used in a webpage. You can get the names, the innertext, innerHTML property of all these tags. The possibilities are endless.
How can we use DOM to access the source page?
We can access the source page of any webpage using .object notation.
Any practical example of using DOM?
I have created a demo web page to show you document object model in action. Say you want to find the font color used for writing Happy Holidays Everyone in cells of the webtable given on this page. The algorithm would be:
- Access the DOM of webtable using .object notation.
- Access the tagname corresponding to the property you wish to find out. In our case tagname is “font” and property to be explored is “color”.
- Find the count of total number of tags and loop it find out the font-color.
The corresponding VB script would be:
Now it’s quiz time. On the same page find out the src of all the images used in the table. Let me know your script through the comments below.
[Also note that src won’t show up in the webtable checkpoint (for obvious reasons!)]
So, what does src say to you?
I wish you Happy Holidays 2009!
Latest posts by Ankur Jain (see all)
- Free Webinar: The Latest In Mobile Test Automation & Extension to QTP - April 20, 2013
- MD5 Checksum: Verify Integrity of UFT(QTP) Download - December 28, 2012
- UFT(QTP) 11.5 is available for download - December 21, 2012