If you are testing web application, you may have used getElementsByTagName method to get access to all elements that have given tag.
Please note that this is not QTP's own method but it is native HTML DOM method.
getElementsByTagName takes one parameter as an input which should be the tag of the element like td, tr, span, div etc.
This method returns the collection of elements that have the given tagname.
Example.
<body>
<div id="head">
This text is inside div element of which id is - head
</div>
<div>
This is another div
</div>
<div>
This is div number 3.
</div>
</body>
In above example, we have sample html document body in which there are 3 div elements.
To get the text value inside all these div elements, we can use the innertext method as mentioned below.
set tn = Browser("myb").Page("myp").object.getElementsByTagName("DIV")
for i=0 to tn.length-1
'print the innertext of each div element here
print tn(i).innerText
next
Thus basically we use getElementsByTagName method to get all element objects with given tag name.
Please note that we can also get the data inside hidden elements using this method. QTP can not read data inside hidden elements.
Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.
Please note that this is not QTP's own method but it is native HTML DOM method.
getElementsByTagName takes one parameter as an input which should be the tag of the element like td, tr, span, div etc.
This method returns the collection of elements that have the given tagname.
Example.
<body>
<div id="head">
This text is inside div element of which id is - head
</div>
<div>
This is another div
</div>
<div>
This is div number 3.
</div>
</body>
In above example, we have sample html document body in which there are 3 div elements.
To get the text value inside all these div elements, we can use the innertext method as mentioned below.
set tn = Browser("myb").Page("myp").object.getElementsByTagName("DIV")
for i=0 to tn.length-1
'print the innertext of each div element here
print tn(i).innerText
next
Thus basically we use getElementsByTagName method to get all element objects with given tag name.
Please note that we can also get the data inside hidden elements using this method. QTP can not read data inside hidden elements.
- 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.
No comments:
Post a Comment
Please Leave your reply. We value your feedback and inputs