Refer:
Http://www.51testing.com /? Uid-173503-action-viewspace-itemid-210466
The HTML Dom defines a standard way for accessing and manipulating HTML documents.
HTML Dom defines a standard method for accessing and controlling HTML documents.
All nodes can be accessed through the tree. Their contents can be modified or deleted, and new elements can be created.
All nodes can be accessed through the tree. Nodes can be modified or deleted, or new elements can be created.
This is the description on w3. We encountered such a problem during the test. One type of information is under a DIV, and as the page information changes, an error is returned when the table object attributes captured by Object repository have changed, the information is not retrieved. For example, if the phone number is 001-0033-3242, three table objects are caught by default, and an error occurs when the index attribute of the table on the page changes. However, they are found under a specific Div, such as divfamilytelphone. developers generally design the page information display in this way.
At that time, I thought of using a program to retrieve the div id and think of the tree structure. So I made the following function, which is a recursive call. I 'd like to share it with you.
Of course, it is based on the DOM definition on W3.
The nodetype property returns the type of node. nodetype is read only.
The Node Type attribute returns the node type, which is read-only.
The most important node types are:
The most important node types are:
Element type nodetype
Element 1
Attribute 2
Text 3
Comment 8
Document 9
In this case, the following functions are implemented in qtp:
1. Master call and return results. The qtp encapsulation method gets the node for parameter call.
Function getmessagebydivid (strdivid)
'If the DIV not found
On Error resume next
Set nodea = browser ("***"). Page ("***"). Object. getelementbyid (strdivid)
If err. Number <> 0 then getmessagebydivid = "": Exit Function
Dim strreuslt
Iteratenode nodea, strreuslt
Getmessagebydivid = strreuslt
End Function
2. recursion, based on the definition of Dom node attributes. Text node return.
Function iteratenode (strnodename, byref strreturn)
'If is a text node, get value.
If strnodename. nodetype = 3 then
Atext = strnodename. nodevalue
Strreturn = strreturn & atext
Exit Function
End if
'For iteration.
Set childnod = strnodename. childnodes
If not isempty (childnod) and childnod. Length <> 0 then
For I = 0 to childnod. Length-1
Iteratenode childnod (I), strreturn
Next
End if
End Function
In fact, later I wanted to implement the same content as the description of qtp. I defined the attribute of the element in the object library and then implemented the text value at runtime. I did not try it. You can try it on your own.