Well - let me tell you that all the properties (parentNode, childNodes, firstChild, lastChild) are not defined by QTP.
All these properties are HTML DOM properties that help us get the child and parent element of the given element in web page.
You can access these method in QTP using .object property which lets you access native methods and properties of the objects/elements.
Example -
<body>
<div id="parentdiv">
This text is inside div element of which id is - parentdiv
<div id="fc">
This is nested div1
</div>
<div id="sc">
This is nested div2.
</div>
</div>
</body>
As you can see in above example, 2 div elements ( fc, sc) are inside the div(parentdiv).
So for fc-div and sc-div, parentdiv is the parent element. While for parentdiv, fc-div and sc-div are child div elements.
You can get access to these elements using HTML DOM properties parentNode, childNodes, firstChild, lastChild.
For example -
'access the child objects
set divParentObject= Browser("myb").Page("myp").object.getElementById("parentdiv")
print divParentObject.firstChild.innerText
print divParentObject.lastChild.innerText
set allchilds = divParentObject.childNodes
for i=0 to allchilds.length-1
print allchilds(i).innerText
next
'access the parent element of div with id "fc"
set childObject = Browser("myb").Page("myp").object.getElementById("fc")
print childObject.parentNode.innerText
This is how we can access the elements using parentNode, childNodes, firstChild, lastChild in QTP.
Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.
If you have any queries, you can drop the comment below.
All these properties are HTML DOM properties that help us get the child and parent element of the given element in web page.
You can access these method in QTP using .object property which lets you access native methods and properties of the objects/elements.
Example -
<body>
<div id="parentdiv">
This text is inside div element of which id is - parentdiv
<div id="fc">
This is nested div1
</div>
<div id="sc">
This is nested div2.
</div>
</div>
</body>
As you can see in above example, 2 div elements ( fc, sc) are inside the div(parentdiv).
So for fc-div and sc-div, parentdiv is the parent element. While for parentdiv, fc-div and sc-div are child div elements.
You can get access to these elements using HTML DOM properties parentNode, childNodes, firstChild, lastChild.
For example -
'access the child objects
set divParentObject= Browser("myb").Page("myp").object.getElementById("parentdiv")
print divParentObject.firstChild.innerText
print divParentObject.lastChild.innerText
set allchilds = divParentObject.childNodes
for i=0 to allchilds.length-1
print allchilds(i).innerText
next
'access the parent element of div with id "fc"
set childObject = Browser("myb").Page("myp").object.getElementById("fc")
print childObject.parentNode.innerText
This is how we can access the elements using parentNode, childNodes, firstChild, lastChild in QTP.
- http://qtp-interview-questions.blogspot.in/2013/06/how-to-use-html-dom-in-qtp.html
- http://qtp-interview-questions.blogspot.in/2013/10/what-is-previoussibling-nextsibling-in.html
- http://qtp-interview-questions.blogspot.in/2013/10/what-is-parentnode-childnodes.html
- http://qtp-interview-questions.blogspot.in/2013/10/what-is-getelementsbytagname-in-qtp.html
- http://qtp-interview-questions.blogspot.in/2013/10/how-to-use-getelementbyid-in-qtp.html
- http://qtp-interview-questions.blogspot.in/2013/10/how-to-get-innertext-of-webelement-in.html
Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.
If you have any queries, you can drop the comment below.
No comments:
Post a Comment
Please Leave your reply. We value your feedback and inputs