Friday 11 October 2013

How to get innerText of webelement in QTP?

In my 10 years of experience in QTP,  I have worked on many web applications that involved jquery, ajax and rich controls.

To test such applications we must have good understanding of the HTML DOM concept.
Extracting the values from the web elements on the page is very common thing that we do in QTP.

To get the inner text or inner html of the web elements, we can use below syntax.

Example -

print browser("bb").page("xys").Object.getElementById("pqr").innerText


Please note that we should use the .object after property before we use html dom.

In above example I am trying to get the text displayed inside web element of which id is "pqr"

We can use more such methods as mentioned below to get access to the web elements on the page
1. getElementById()   - get the element by id
2. getElementsByTagName() - get all elements with given tag name
3. getElementsByClassName() - (does not work in < ie9) - get all elements having given class
4. getAttribute() - get the value of attribute of given node
5. getAttributeNode() - get the attribute node
6. hasAttribute()  - check if a node has given attribute
7. hasChildNodes()  - check of node has any children
8. item() - access the node based on the index from the collection

Once we get the element object, we can use below properties to get the data.
1. innerHTML – gets the html code inside element
2. innerText  - gets the text value inside element
3. getAttribute – gets the value of attribute
4. nodeName  - (like TD, SPAN, #text, #document, Attribute name)
5. nodeType   - (Element, Text, Attribute, Comment, Document)
6. nodeValue  - (attribute Value)
7. childNodes   - gets all child elements of the given node
8. attributes   - gets the collection of all attributes of given node
9. className   - gets the name of class of given element
10. firstChild    - gets the access to first child element of the given node.
11. Id – gets the id of the given node.
12. lastChild – gets the last child element of the given node
13. nextSibling – gets the next element at the same level as given node.
14. offsetLeft
15. offsetTop
16. previousSibling - – gets the previous  element at the same level as given node.
17. parentNode –gets the parent node of the given node
18. scrollLeft
19. scrollTop
20. scrollWidth
21. style   - gets the style information of the given node
22. tagName – gets the name of the tag of given node
23. textContent – gets the text displayed inside given node
24. title  - gets the title of the given node
25. length – gets the total number of nodes in the collection.

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.