GetRoProperty, GetToProperty in QTP/UFT with Example
⚡ Smart Summary
Object Spy reveals the properties and methods of any control in the application under test, while GetROProperty, GetTOProperty and SetTOProperty read and write those property values from a QTP or UFT One script at run time.

This tutorial demonstrates Object Spy.
Object Spy can help determine the useful properties and methods associated with an object in your environment.
The HP/Micro Focus UFT tutorials also describes GetROProperty, GetTOProperty & SetTOProperty.
⚠️ Version note: The tool described here shipped as HP QuickTest Professional, became Micro Focus Unified Functional Testing, and is sold today as OpenText Functional Testing (UFT One). Object Spy and all three methods still work exactly as described below.
Click here if the video is not accessible
Object Spy
- Object Spy is a feature in QTP using which you can view both the test and run-time object properties and methods.
- It also gives the syntax for a selected method.
- Object Spy gives the complete hierarchy of the object you have selected.
That hierarchy matters, because a property name copied out of Object Spy is the exact string the three methods below expect. Spying an object is therefore the first step in almost every property retrieval task.
GetROProperty
- GetROProperty – is an inbuilt method used to retrieve the runtime value of an object property.
There are 4 steps involved in using the GetROProperty:
- Record the Object on which you want to use the GetROProperty in Object Repository.
- For the recorded object identifies the run-time property which could be used. You may use Object Spy.
- Use GetROProperty method to retrieve the identified Run-time property and store the value in a variable.
- Use this value for further deductions.
Because the value is read from the live control, the application must be open and the object must actually exist on screen when the line runs.
SetTOProperty & GetTOProperty
- Consider a Web Button stored in the Object Repository
- When the test is run QTP creates a copy of this object called Test Object and compares it with the Run Time Object
- Using GetTOProperty you can retrieve the value of a property of Test Object
- Using SetTOProperty you can change the property value of a Test Object
- When the test is completed, this test object is discarded and so are any modifications you made in the object properties using the SetTOProperty
- When the test is re-run, a new copy of the test object is created with original property values stored in the object repository
- You can consider using GetTOProperty and SetTOProperty when your test script has multiple lines of codes and your environment is sporadic
- For a note, there is no SetROProperty
Syntax and Examples
All three methods are called on a test object at the end of its hierarchy, and all three take a description property name as a string. The table gives the signature of each.
| Method | Syntax | Reads or writes |
|---|---|---|
| GetROProperty | object.GetROProperty(Property) | Reads the live control in the application |
| GetTOProperty | object.GetTOProperty(Property) | Reads the stored test object description |
| SetTOProperty | object.SetTOProperty Property, Value | Writes the test object description for this run only |
Reading a run-time value is a single statement. This example, taken from the official retrieve and set values reference, pulls the target address of a link during the run session.
link_href = Browser("Technologies").Page("Technologies").Link("Jobs").GetROProperty("href")
Writing then reading a test object property is just as short. The pair below sets the Submit button name to my button and reads the same value straight back.
Browser("QA Home Page").Page("QA Home Page").WebButton("Submit").SetTOProperty "Name", "my button" ButtonName = Browser("QA Home Page").Page("QA Home Page").WebButton("Submit").GetTOProperty("Name")
A typical verification joins the two ideas: read the run-time value with GetROProperty, then compare it against what the test expects.
strValue = Browser("Welcome").Page("Find a Flight").WebList("fromPort").GetROProperty("selection") If strValue = "Acapulco" Then Reporter.ReportEvent micPass, "Default city", "Default city is correct" Else Reporter.ReportEvent micFail, "Default city", "Unexpected value: " & strValue End If
Difference Between GetROProperty and GetTOProperty
The two names differ by one letter and are the most confused pair in the tool. RO stands for run-time object, TO for test object, and each reads from a different place.
| Point of comparison | GetROProperty | GetTOProperty |
|---|---|---|
| Source of the value | The live control in the running application | The description stored for the test object |
| Application must be open | Yes | No |
| Sees a SetTOProperty change | No | Yes, for the current run |
| Typical use | Verifying what the user actually sees | Checking or debugging how the object is being identified |
| Matching setter | None — there is no SetROProperty | SetTOProperty |
A worked contrast makes the split obvious. Set an html id on a list that has none, then read it back both ways: GetROProperty returns an empty string because the application never changed, while GetTOProperty returns the value that was just written into the description.
Common Errors and How to Fix Them
Property retrieval fails for a small number of predictable reasons. The table lists the ones testers meet most often.
| Symptom | Cause | Fix |
|---|---|---|
| The call returns an empty string | The property name is wrong, or the object does not expose it | Spy the object again and copy the property name exactly as listed |
| Object not found at the GetROProperty line | The control had not rendered yet | Add a synchronisation step before the read |
| GetROProperty ignores a SetTOProperty change | The two methods address different objects by design | Read the change back with GetTOProperty instead |
| A SetTOProperty change disappears | Test object edits last only for the current run | Edit the object in the repository, or use descriptive programming |
| SetROProperty raises a syntax error | No such method exists | Drive the application through a normal step such as Set or Click |
Two habits prevent most of these: spy the control before writing the line rather than guessing the property name, and keep VBScript retrieval calls close to the step that needs the value, so the object is still on screen when the read happens.
