Friday, 11 October 2013

How to use getElementById in QTP?

I know that you have come on this page because you are testing the web application.
Web application testing is very interesting stuff.

Apart from normal web methods and  properties provided by QTP, you can use lot of native methods of the web elements.

One of such native method of the document object is  getElementById.
This method takes one parameter as an input which should be the id of the element.

Example.

<body>
<div id="head">
 This text is inside div element of which id is - head
</div>
</body>

In above example, we have sample html document body in which there is one div element with id = 'head' and it contains some text.

To get the value inside this div element, we can use the innertext method as mentioned below.

print Browser("myb").Page("myp").object.getElementById("head").innerText

So output of above code will be.

"This text is inside div element of which id is - head"

Thus basically we use  getElementById method to get the element object and then we can use its innerText method to get the data inside that element.

Please note that we can also get the data inside hidden elements using this method. QTP can not read data inside hidden elements.

You can find all concepts on QTP (UFT) on Master Page.
This is how we can use html dom in qtp to get the information displayed on the webpage. This makes the web application testing quite easy stuff.
  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.