You are on page 1of 4

5/8/2018 QTP: How to Use HTML DOM in QTP?

More Next Blog»

Non-Technical Stuff

Double your money QTP Stuff Searc

Buy QTP + Selenium Books


QTP Hot Links
Watch QTP videos
QTP Master Page
Buy Q
Basic QTP Tutorial For Beginners
Wednesday, 19 June 2013
Advanced QTP tutorial For Experienced
professionals You m

Basic QTP interview Questions and answers for


How to Use HTML DOM in QTP? QT
Freshers
Well - If you are testing a web application then you will know the limitations of QTP as far as Ind
Advanced QTP Interview Questions and Answers
For Experienced Guys identification of objects is concerned. Ga

QTP - Vbscript interview questions and answers Exc


Many web objects have same properties. So QTP tries to identify the objects using Index - Ordinal Se
You may also like Vbscript Blog
Identifier. Qu
Download QTP and Selenium books pdf
Mis
The disadvantage of using index is that It makes the script weak. What I mean here is that If developer Vb
QTP Stuff adds new objects of similar types, Index of the existing objects also change. So QTP fails to identify Qu
the object due to changed index.
Buy best QTP + Selenium Books
Watch QTP Videos QTP S
So How you can use HTML DOM to handle such scenarios.
Wa
Popular Tutorials Using html DOM you extract all kind of information from page as you can access source code of the Buy
Bo
page in the form of HTML.
Selenium + Java Tutorial
Selenium + C#.Net Tutorial HTML DOM has many method and properties associated with it like getElementById, nextsibling etc.
C Language Programming

To access these methods you must create the DOM object first.
More QTP Concepts Trans
Syntax to create a DOM object is -
► 2014 (39) S
▼ 2013 (223) Set domObject = Browser("myb").Page("myp").object
► November (19)
► October (12) Above statement will create the DOM object for the page called myp.
► September (1)
Now You can access the methods of the DOM object
► August (24)
► July (13) Now let us use the dom object we have created above to get more information of the page currently
▼ June (1) displayed in the application.
How to Use HTML DOM in QTP?
Print domObject.getElementById("myid").innerText ' Prints the text inside the Element - myid
► March (153) Print domObject.getElementById("myid").innerHTML ' Prints the inner HTML of Element - myid

How to access the parent object of given DOM Object


Most Popular QTP Posts

QTP questions and answers for Experienced You can also find the parentobject, nextsibling, previoussibling of the given dom object using built in
properties as mentioned below.
Advanced QTP Interview Questions and answers
Set parentObj = domObject.getElementById("myid").parentNode ' gets the parent object of myid
Keyword Driven Automation Framework in QTP Set nextsiblingObj = domObject.getElementById("myid").nextsibling 'gets the next sibling object of
myid
How to define Array in QTP
Set previoussiblingObj = domObject.getElementById("myid").previoussibling
How to open any website(URL) in browser
(IE,chrome, firefox) in QTP?
Ok ..Now you are able to create DOM object...What Next?
Difference Between vbs and qfl files in QTP

RepositoriesCollection Object in QTP Once you have created the DOM Object, you can access the text associated with that object. After
getting the text you can process that as per your testing requirement.
Learn QTP Core Concepts
Print domObject.getElementById("myid").innerText ' Prints the text inside the Element - myid
How to Use HTML DOM in QTP? Print domObject.getElementById("myid").innerHTML ' Prints the inner HTML of Element - myid
Difference Between QTP 10 and 11
In above examples, I have used only getElementById method. But there are lot of other methods that
you can use. For complete list of methods you can
visit http://www.w3schools.com/jsref/dom_obj_node.asp

Some of the example of html dom in QTP are given below.

How to get the collection of all TD (table data cells) elements of the table using HTML DOM in
QTP?
Set tdtags
=Browser(“abc”).Page(“mypage”).WebTable("mytable").Object.getElementsByTagName("TD")

How to get the collection of all TH (table header cells) elements of the table using HTML DOM in
QTP?

http://qtp-interview-questions.blogspot.in/2013/06/how-to-use-html-dom-in-qtp.html 1/4
5/8/2018 QTP: How to Use HTML DOM in QTP?
set thtags =
Browser(“abc”).Page(“mypage”).WebTable("mytable").Object.getElementsByTagName("TH")

How to get the value of attribute of any element using HTML DOM in QTP?
Set myobj = Browser(“abc”).Page(“mypage”).WebTable("mytable").Object
Print myobj.getAttribute("class") 'This will print the value of class attribute of myobj - table

How to get the collection of all table rows using HTML DOM in QTP?
Set tableObj =Browser(“abc”).Page(“mypage”).WebTable("mytable").Object
Set trtags = tableObj.getElementsByTagName("tr")

How to find the total number of rows in table Using HTML DOM in QTP?
print trtags.length

How to get the value inside table cell Using HTML DOM in QTP?
Set tdtags
=Browser(“abc”).Page(“mypage”).WebTable("mytable").Object.getElementsByTagName("TD")
Print tdtags(0).innerText 'print the text displayed inside first td tag in table

********************************************************************************
You can also find below links related to HTML DOM very useful.

1. previousSibling in QTP
2. parentNode and childNodes in QTP
3. getElementsByTagName in QTP
4. getElementsById in QTP
5. Get innerText of the web Element in QTP
6. Find total number of rows in table
7. Trigger web events in QTP.
8. Find all web list objects in QTP.

You can visit QTP-UFT Master Page.


If you have any issues in object identification of web objects like Webedit, WebElement etc you can
drop your comments below. I will respond to them quickly.

Posted by Sagar S at 00:40

http://qtp-interview-questions.blogspot.in/2013/06/how-to-use-html-dom-in-qtp.html 2/4
5/8/2018 QTP: How to Use HTML DOM in QTP?

6 comments

Add a comment

Top comments

Norman Walter 4 years ago  -  Shared publicly


I  am working with a page which has a frame and the objects I want to access are
within the frame and them within two web tables - how do I access them using
the DOM  - I want to click on the link using Descriptive Programming.

Thanks...

+1 1  ·  Reply

Sagar S (Vishal) 4 years ago


 This can be easily done using getElementsByTag method. 

maruthi sunil 6 months ago  -  Shared publicly


 Very useful and valuable info.....thanks a lot

1  ·  Reply

Milan Das 4 years ago  -  Shared publicly


 helpful

1  ·  Reply

Praveen Kumar 1 year ago  -  Shared publicly


 
Valuable information thanks for sharing <a href="http://cheyat.com/qa/uft-online-
training-and-tutorials"> UFT Online Training </a>

1  ·  Reply

Sagar S (Vishal) shared this via Google+ 4 years ago  -  Shared publicly
  1  ·  Reply

Newer Post Home Older Post

Subscribe to: Post Comments (Atom)

Best QTP Books

QTP Stuff

Watch QTP Videos


Buy QTP + Selenium 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.

Subscribe To QTP

Posts

Comments

Google+ Followers

http://qtp-interview-questions.blogspot.in/2013/06/how-to-use-html-dom-in-qtp.html 3/4
5/8/2018 QTP: How to Use HTML DOM in QTP?
Sagar S (Vishal)
Add to circles

277 have me in circles View all

http://qtp-interview-questions.blogspot.in/2013/06/how-to-use-html-dom-in-qtp.html 4/4

You might also like