QTP Descriptive Programming - How to get number of objects

QTP Descriptive Programming - How to get number of objects

I'm going to explain and show QTP Descriptive Programming (DP) through Google Sets site:
(click image to enlarge it)

The goal of the present QTP tutorial is to describe:
How to get number of controls (Links, Edits, Images, etc) with QTP DP.

Let's investigate Descriptive Programming on examples.
First of all, we should understand what Descriptive Programming means:
What is QuickTest Professional Descriptive Programming (QTP DP)?

QTP DP is a run-time processing of objects which are not located in QTP Object Repository.

I've created new QTP script which starts with http://labs.google.com/sets page.
This QTP script is simple enough:
Set Desc = Description.Create()
Desc("micclass").Value = "WebEdit"
Set Edits = Browser("Google Sets").Page("Google Sets").ChildObjects(Desc)

MsgBox "Number of Edits: " & Edits.Count

And its result is:
As you can see, it works correctly and returns correct number of Edits on a page.
I'm going to explain this QTP script and answer the following question:

How does QTP Descriptive Programming work?

First of all, I've created new Description object:
Set Desc = Description.Create()
Description object contains collection of properties, which identify any UI object such as a browser, a page, a dialog, a list, a button etc.

To specify that we want identify all Edits on browser's page I use
"micclass" property:
Desc("micclass").Value = "WebEdit"
Note: the "mic" prefix in "micclass" stands for "Mercury Interactive Constant".

How do you know the class name ("micclass") of object?

Use Spy for that:
QTP Object Spy
Open QTP object Spy and check recorded properties of object.
For example, these are properties of Edit:
QTP Object Spy - recorded properties
As you can see, there is "Class Name" property and its value - "WebEdit". So, "WebEdit" is a value of Class Name of all Edits located on Web page.
"Class Name" is a synonym of "micclass".

I gathered Class Names of Web objects in this table:

Type of Web object
Class Name(micclass)
Web Browser
Edit box
Web Element
Combobox (DropDownList)

Since we created Description object for all edit boxes, we can use this description to get all specified objects ( = edit boxes).
The next step
returns the collection of all child objects (i.e. edit boxes) contained within the page:
Set Links = Browser("Google Sets").Page("Google Sets").ChildObjects(Desc)

To get the number of found objects in a returned collection, we use Count property:

MsgBox "Number of Edits: " & Links.Count

And the result is 5 found Edits on Google Sets page:
Number of Edits
So, this is a mechanism of QuickTest Professional Descriptive Programming.

Also, we can use the same code to get number of others objects - Links, Images, Buttons, etc.
For that I modified QTP script:

Function GetAllSpecificControls(Page, MicClass)
    Set Desc = Description.Create()
    Desc("micclass").Value =
    Set GetAllSpecificControls = Page.ChildObjects(Desc)
End Function

Function GetAllEdits(Page)
    Set GetAllEdits = GetAllSpecificControls(Page, "WebEdit")
End Function

Function GetAllButtons(Page)
    Set GetAllButtons = GetAllSpecificControls(Page, "WebButton")
End Function

Function GetAllLinks(Page)
    Set GetAllLinks = GetAllSpecificControls(Page, "Link")
End Function

Function GetAllImages(Page)
    Set GetAllImages = GetAllSpecificControls(Page, "Image")
End Function

Set oPage = Browser(
"Google Sets").Page("Google Sets")

MsgBox "Number of Edits: " & GetAllEdits(oPage).Count
MsgBox "Number of Buttons: " & GetAllButtons(oPage).Count
MsgBox "Number of Links: " & GetAllLinks(oPage).Count
MsgBox "Number of Images: " & GetAllImages(oPage).Count

The result of this QTP script is the following:
Results of QTP script
You can compare the result with the initial web page (see first image in the present article) and verify that QTP Descriptive programming works correctly - it returns correct numbers of objects.

  • I've explained and shown the mechanism of QuickTest Professional Descriptive Programming (QTP DP).
  • The present QTP tutorial explains how to get number of different objects - Edits, Links, Images, Buttons, etc.

I hope, that this article has helped you to understand QTP DP.
The future QTP tutorials will cover others questions on QTP Descriptive Programming.

Related articles:

Have you got interested materials or your own thoughts on QTP (QuickTest Professional)?
Let's share them and help each other to improve our skills and knowledge!
You can send them to my email: Dmitry Motevich's email

Thank you in advance, dear readers.


George said...

Good going Dmitri....the "mic" abbreviation was new to me :) thanks a lot.... Is there any situation where we will use Descriptive Programming "ONLY" for automation... i.e. without using record and play ? Is that advisable and efficient?

Anonymous said...

I copied and pasted the script in my QTP window and tried running the script which kept getting runtime error at line 3:
Set Links = Browser("Google Sets").Page("Google Sets").ChildObjects(Desc)

Do I need to record anything in QTP or do something in Object repository before running the script?

Thanks for the input.

SAP said...

script does not work..causes runtime error..i copied n pasted the script

Dmitry Motevich said...

Yes, you should open Google Sets page and add it into QTP Object Repository (OR
The following construction:
Browser("Google Sets").Page("Google Sets").
uses browser and page defined in OR.

Dmitry Motevich said...

It works! If you can start it :)
I've just shown how to run it. See my above comment

coolguy123 said...

i like qtp scripting and currently working on it.i have some doubt in DP ,SO KINDLy explain it with example with more DP videous, it will be helpfull for me and everybody.


Dmitry Motevich said...

Please motivate me to create videos on DP :)

Anonymous said...

It was really excellent code mentioned here and really hardwork done bt you. :)

I have a samll query incase it looks interesting to all of you.

I have a portal where 10links are appeared at every page. I need to click each of them but for this I need to add all 10objects in OR so if I have 100 pages then its 1000 objects in OR which is no good.

So can u suggest some code where we can use one generic object in OR to click all 10links each time.


Dmitry Motevich said...

Please read Related articles for the present one.

I think QTP Descriptive Programming - How to perform operations on objects will help you to get all required links and perform operations on them, for example to click them.

Raj said...

Hi, can you help me in capturing a checkbox value using GetRoProperty please

Dmitry Motevich said...


Anonymous said...

kudos man, you have done great job..we are sincerely saying thanks..keep continue..we have question for you. We cannot able to identify file or edit in menu bar, it is showing all objects as one object could u plz send code for this..my email id:sirihari3@yahoo.co.in

Dmitry Motevich said...

Please send your question to QTP group

Anonymous said...


I am getting an error on this line of code: Set Edits = Browser("Google Sets").Page("Google Sets").ChildObjects(Desc)

I have added the all the related objects in the Object Repository before running this script. Also, tried to debug it, it is giving unspecified error.

Please update on this if possible.


Dmitry Motevich said...

Please read this topic.
I'm sure I contains the answer for your question.

Anonymous said...

I am getting an error on this line of code: Set Edits = Browser("Google Sets").Page("Google Sets").ChildObjects(Desc)

Kindly help me to solve it


Dmitry Motevich said...

to Anonymous/Anit,
Answered in above comments.

Anonymous said...

your videos on o/p values is really superb.
I have problem in "QTP Descriptive Programming - number of objects" in that by using object spy it shows two webtables after that webedit is displayed
Yesterday i worked correctly i got the proper o/p what you said.
Now i got this error
could you explain me for reason this happens

Dmitry Motevich said...

How can I explain reasons of the error if you didn't provide the error message?

Niki said...

Thanx..u r doing a gr8 job

can u pls let me know whts wrong in here....I m getting a general run error....

Set brodesc=description.Create()
brodesc("title").value="Google Sets"

Set pagedesc=description.Create()
pagedesc("title").value="Google Sets"

Set linkdesc=description.Create()

Set alllinks=page(pagedesc).ChildObjects(linkdesc)
msgbox"No. of links "&alllinks.count

Dmitry Motevich said...

You missed Browser object.

Change this line:
Set alllinks=page(pagedesc).ChildObjects(linkdesc)
like this:
Set alllinks=browser(brodesc).page(pagedesc).ChildObjects(linkdesc)

Johnson said...

Dimitry thanks for your response

yesterday i ask doubt in


Initially i got the code as

Browser("Google Sets").Page("Google Sets").Sync
Browser("Google Sets").Close

after that i modified what you said in your blog and run the script, it shows "general run error"
In OR browser and page only present

am i correct i think u understand my doubt.
please i want this ouput in my system
what can i do

Dmitry Motevich said...

I do not see your yesterday's comments.
Also, plese provide detailed info about your issue - source code, error message, line#, what did you try and its resutls, and so on.
Since you didn't provide such info, I cannot answer.

Johnson said...

i got the output motevich by the method using in images

At bottom u gave the tips u know.

thanks dmitry

Niki said...

Even if I use this description for browser,

Set brodesc=description.Create()
brodesc("title").value="Google Sets"

I have got to add the browser object to the object repository....only then I m not getting the general run error in line

Set alllinks=browser(brodesc).page(pagedesc).ChildObjects(linkdesc)

why is that?

Niki said...

Hi dmitri

I m sorry...actually it works fine even without adding the browser object to the OR

the mistake that I have done was
I have used

instead of


(capital 'L' in "link")


Ganesh Babu N R said...

In v9.5 this code should be corrected :
Desc("micClass").Value = "WebEdit"
has to be
Desc("micclass").Value = "WebEdit"

"micClass" results in an Run Time error.

Just an FYI :-)

Thanks to the article Dmitry

Dmitry Motevich said...

@Ganesh Babu N R,
You are right. Thank you!

I've edited the article and changed "micClass" to "micclass".
BTW, on screenshots I used correct form ("micclass").

Thank you for attention, Ganesh. :)

sheeba said...

Thanks, it was very useful

Yesh said...


Your article gives a good insight in to Descriptive programming using QTP.

I have a question though. Doesn't one use DP to avoid using the OR. Feels like using OR defeats the purpose of introducing DP in to your testing.


Dmitry Motevich said...

The main purpose to use DP is a processing of dynamic objects (buttons, edits, link).
You can know properties of such objects during run-time session only.

That;s why you cannot create these objects into OR.

Anonymous said...

Thank you very much for all of your articles. They are fantastic.I learned a lot. I have a question here. when I run this program it is giving number of edit class =0 in message box.
what did I do wrong.Could you please tell me

Dmitry Motevich said...

@Anonymous (January 29, 2009),
Maybe, you didn't open an initial page (Google Sets).

Anonymous said...

Hi Dmitri,

i have a webedit inside the webtable in my application.

i need to set a value in the webedit.....can u help me with the function.

bade raju said...

I became a big fan your site, and using most of your code skills in my current project.
I have an object by name CUSTNUM and its created thru OR. Now the same object during run time i want to capture the object and update the OBJ CUSTNUM. I am able to capture the object during runtime but i dont know how to update the object onto OR.
Any help is greatly appreciated.

revaraghavan said...

how to SelectAll text(CTRL+A) using QTP mine is an edit box in the application.I tried Sendkeys not working..Pls help

revaraghavan said...

How to SELECTALL text(CTRL+A) in qtp.Send keys aint working.pls help

Sandhya said...

I copy pasted the code.
I also opened the google labs page and created the object in OR.

I still get the error message as "Google Sets" Browser object was not found in OR. Check the OR to confirm that object exists or to find correct name for the object.

Please help me to proceed.

Bisht said...

How to Write a DP for following web site:(object spy display 6 thing in this web page)

WebTable:Parent Registraion
WebTable:Parent Registraion (Again)

Usha said...

Can we do the same thing to count the number of objects in a window application?