QTP Tutorial #7 – QTP’s Object Identification Paradigm – How QTP Identify Objects Uniquely?

How Does QTP Identify Object Uniquely? – This is the 7th QTP Tutorial in our QTP training series.

We are getting ourselves equipped with all the basic concepts that will enable us to write robust QTP tests. We have covered the QTP Record and Run settings, Working with Keyword view, and the other related topics.

=> Click Here For QTP Training Tutorials Series

Object Identification Paradigm

This is the next article in the series that talks about a crucial aspect of QTP – The mechanism it uses to identify an object uniquely.

QTP login dialog

How Does QTP Identify Object Uniquely

When you look at the screen above, there are 3 buttons and 2 text boxes along with various other elements in this dialog.

In the previous examples, when we entered the username and password we saw how QTP recorded the same operations in terms of programmatic code as well as a table in keyword view. Now, during playback how does QTP know that the value we provide as Agent Name or Password has to go respectively in those edit boxes. Or how do you know which button to click to submit the values entered?

Let us try to find the answer to that.

It is clear that QTP somehow remembers which object to act on. The way it does it is, it stores the object in the AUT as a test object. It then examines its properties and classifies the object. For Example, when it encounters the OK button, it examines its properties, and based on these, it classifies the object as a “WinButton”.

QTP has a predetermined set of properties that it learns/stores for every class of object it identifies.

There are 3 aspects to this:

  • Mandatory properties: This is the list of properties for a certain class that QTP always stores. We could say that this is the object description. It also checks this in conjunction with the parent object to see if the description is sufficient to identify the object uniquely.
  • Assistive properties: In case the description of mandatory properties is insufficient to identify the Object, a set of non-mandatory properties will be added to the description one after the other until there is enough data to identify the object.
  • Ordinal Identifier: If the assistive properties also do not result in a unique identification of an object a special ordinal identifier is added by QTP, such as the object’s location on the page or in the source code.

So, this is how QTP forms Test Objects. It uses this Test Object description to search for objects to act on during a run session. It chooses objects that match perfectly with the description it contains. These objects are called Run-Time objects.

Unless your application has significantly changed the Test Object description that QTP has is sufficient to find an object.

For the WinButton object that we have in our Flight app, let us see what properties QTP has stored. This information is available in the Object Repository. The menu option “Resources -> Object Repository” will launch the OR for us. Alternately, you can use CTRL+R or click on the icon.

QTP Object Repository

If you notice in the above window, it stored the ‘text’ in the WinButton as its description to identify this button at runtime.

For more complicated applications, the tester can add or remove certain properties to make the description robust enough to identify the object at runtime more precisely. To do this, simply click on the ‘+’ icon.

QTO Object Properties

All other properties of the object will be displayed. The user can choose to add one or more of these properties.

There is also something called “Visual Relation Identifier” in the OR screen for the WinButton properties.

This is a feature that further supports object recognition according to their neighboring objects in the AUT. Once set, this creates a kind of link for the less stable components in your AUT with the objects that are more uniquely identifiable.

QTP will identify these objects as long as they maintain their relative position to these unique objects. To set a kind of positional link, we are going to click on this column in the OR and the following screen will come up.

QTP Visual Relation Identifier

On this screen, select the ‘+’ sign to add an object with which you want your test object to have a positional link.

I will choose “Agent Name” and say that this object should be above the “OK” button.

This is how I set it up:

QTP Visual Relation Identifier 2

Now, in case some properties of the OK button change in the future, then QTP will identify it if, the “Agent Name” is above it.

Smart Identification

This is the mechanism employed by QTP under one of these two situations.

The description for an object that QTP has:

  • Does not match with any runtime objects.
  • Matches with multiple objects.

This is a little bit of an advanced concept, so we will get to it at a later time via some examples for easy and elaborative understanding.

Ordinal Identifier

This is a numeric value that depicts the relative order of the object with objects that have a similar description. If Object 1 and Object 2 have the same mandatory and assistive properties, then the ordinal identifier will be used to recognize the object uniquely.

This value is related to the other objects of the screen, so in case anything changes in the screen, then this identifier might not come useful.

It should be noted that, if the mandatory and assistive properties are enough then an ordinal identifier is not assigned to record. It can be added later on by clicking on the respective column for the object in the OR.

There are 3 kinds of Ordinal Identifiers:

  • Index: This is based on the order of appearance of an object in the application code.
  • Location: Based on the location on the screen, dialog, or page.
  • Creation Time: This is used only for browser objects. In case 2 browsers with similar properties exist, then the one that is created first and the next is considered.

For Example, let us understand how the ‘index’ identifier works in our Flight applications login screen:

These are the following components:

QTP Test objects

As you can see, the static text and the edit boxes have the same ‘text’ property.

If I know that one of them is a static text and the other is a WinEdit object, then there is no problem at all. Say if all these are treated as WinObject then I will have to specify which object to act on.

This is only going to happen when mandatory, assistive and smart identification has failed. So in order to tell QTP which is what, I am going to assign an ‘Index’ ordinal identifier. I will do so from OR.

QTP Ordinal Identifier

I will set the Agent name static text identifier as 0 and for the edit box, I will set it as 1.

This is how it looks:

QTP Object properties

If I need to access the static text then I will do so as follows:

WinObject(“text:=Agent Name:”, index:=0) – This will refer to the static text

WinObject(“text:=Agent Name:”, index:=1) – This will refer to Edit box

The same theory applies to the Location identifier too except that we will choose the location in the window to determine the numeric value that is applicable to a certain object.

Configuring Object Identification Properties:

The mandatory, assistive properties and ordinal identifiers to be considered for an object of a certain class to be recognized can be configured by using “Tools -> Object Identifier”. We can also set up smart identification properties through this window.

The window looks as follows:

QTP Configuring Object identification properties

As seen in the above image, the environment can be chosen from the drop-down box. Once that is chosen, the classes of objects in the corresponding environments are shown in the list. After an object is selected, the mandatory and assistive properties are displayed. The user can Add/Remove additional properties to this list.

Also, smart identification can be enabled/disabled for a certain class of objects when needed. To set the ordinal identifier there is a drop-down that can be chosen to identify the object using Location, Index, or Creation Time (only for browser type only).

We will wrap up the fundamental concepts before moving on to full-fledged QTP programs. The next QTP article will have different recording modes, Object Spy, Object Repository, etc. in detail.

=> Visit Here For The QTP Training Tutorials Series

Recommended Reading

18 thoughts on “QTP Tutorial #7 – QTP’s Object Identification Paradigm – How QTP Identify Objects Uniquely?”

  1. great article!!!
    can we manually specify object details if it is not identified by QTP?

  2. please explain what are all test automation framework>

  3. @Suresh: Yes, there are various ways in which you can make QTP identify and act on an object. You could use Virtual objects or you can use descriptive programming. Both these topics are going to be discussed in the future sessions

  4. @Atul: All the frameworks are going to be explained in the coming articles

  5. Very Nice article…
    I never understood these object identification perfectly before.

  6. Really Superb Article, It help me to learn the QTP Basics. Will looking for smart Identification article soon,

  7. How to play a video in vlc player by writting qtp script or vb script. I need the script.

  8. how to read the index using object spy?

  9. @kiran: Try to spy the object whose index you want to find out during run time. location Ordinal identifier is the property you are looking for.

  10. How do I spy/identify an image of window object?

  11. what is smart identification????????

    plz reply…………………………………………………………..

  12. Hi Sriram,
    If QTP can’t determine a object from repository, when running a test, with smart Ident. QTP try to find a correspondenting object. So smart identification is useful when you create test, but it needs performance.
    Hope it helps.

  13. Please Tell me how can use recovery scenario in qtp

  14. Awsome article..Cleared most of the concepts of object identification.

  15. Hi,
    I am new to QTP.
    Why below code is not working? I am trying to pass the pageName dynamically
    Browser(“Browser”).Navigate linkURL
    pageName = Browser(“Browser”).Page(“micclass:=Page”).GetROproperty( “title” )
    Browser(“Browser”).Page(pageName).WebEdit(“Write something…”).set(msg)
    Please help me on this!

  16. Why do we need to identify objects by different methods. Give some practical example in a tester’s way

  17. How to get list of identification properties of an object using descritive programming

  18. Which is more effective mechanism for object identification – Ordinal identifiers or XPath


Leave a Comment