Friday 11 October 2013

What is getElementsByTagName in QTP?

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.


  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.