QTP Dom

What is Document object Model?
A platform- and language-independent standard object model for representing HTML or XML and related formats.


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:

1. Access the DOM of webtable using .object notation.
2. 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”.

3. Find the count of total number of tags and loop it find out the font-color.

The corresponding VB script would be:

set font=Browser("B").Page("P").WebTable("H").Object.all.tags("font")

msgbox font.length

For i=0 to font.length-1
Msgbox font(i).color
next

XML Code To Get Root Child Nodes

On error resume next
Set xmlDoc = XMLUtil.CreateXML()
'loadXML
xmlDoc.LoadFile("C:\ApplyWeb_getPrescreenData.xml")
If Err.Number <> 0 Then
Msgbox "Invalid XML"
End If
Set Root = xmlDoc.GetRootElement()
Set objChildNodes = Root.ChildElements()
numberof = objChildNodes.count()
msgbox numberof
On error goto 0 

Encrypt PWD

str = "Some Text"
encrStr = Crypt.Encrypt(str)

0 comments:

Post a Comment