Friday, 11 October 2013

What is previousSibling, nextSibling in QTP?


Well - let me tell you that  all the properties (previousSibling, nextSibling ) are not defined by QTP.

All these properties are HTML DOM properties that help us get the elements at the same level 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. The div elements fc-div and sc-div are siblings of each other as both are at same level.
sc-div is the nextSibling of the fc-div. While fc-div is the previousSibling of the sc-div.


You can get access to these elements using HTML DOM properties nextSibling, previousSibling properties

For example -
'access the next sibling of fc-div
set obj= Browser("myb").Page("myp").object.getElementById("fc")
print obj.nextSibling.innerText

'access the previous Sibling of sc-div
set obj= Browser("myb").Page("myp").object.getElementById("sc")
print obj.previousSibling.innerText

This is how we can access the elements using  previousSibling, nextSibling in QTP.

You may find below links very useful
  1. http://qtp-interview-questions.blogspot.in/2013/06/how-to-use-html-dom-in-qtp.html
  2. http://qtp-interview-questions.blogspot.in/2013/10/what-is-previoussibling-nextsibling-in.html
  3. http://qtp-interview-questions.blogspot.in/2013/10/what-is-parentnode-childnodes.html
  4. http://qtp-interview-questions.blogspot.in/2013/10/what-is-getelementsbytagname-in-qtp.html
  5. http://qtp-interview-questions.blogspot.in/2013/10/how-to-use-getelementbyid-in-qtp.html
  6. 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.

No comments:

Post a Comment

Please Leave your reply. We value your feedback and inputs

Best QTP Books

Everything About QTP

Hello Friends,
You can find QTP study material, Multiple choice questions (mcq), QTP question bank, QTP question papers, QTP notes, QTP questionnaire, scenario based QTP interview questions, QTP tutorial and QTP training on this site.

If you are a fresher or experienced QTP professional with (1/2/3/4) years of experience, this blog is just for you.