Wednesday, March 9, 2011

How to deal with Dynamically changing Objects in QTP?

We come across this situaltion quite frequently. How do we deal with a dynamic object/continuously changing object at the runtime. May be the object's properties are set dynamically at runtime through input parameters. We are now at a point where we cannot add this object to the OR (Object Repository).

So what's the solution?

It is simple, create a dynamic/runtime object.

How do I define/create a dynamic object?

  • First Method:(method is explained inline)
Set newObject = Description.Create
'The above line declares a new object

newObject("micclass").Value = "WebElement"
'The above line sets the type of object (Browser/Page/WebElement/Link etc), in this case it is a Web Element

'The below 3 lines set the Dynamic/Runtime properties of the object

newObject("html tag").Value = "SPAN"
newObject("class").Value = "radio-classic-ITEM-OFF"
newObject("text").Value = Parameter("Text")

'Usage of the new Object
  • Second Method
The following syntax can be handy for one time usage of a Dynamic Object. In this method we set the properties of the dynamic object in the same line. This is another way of implementing the above example.
Browser("Google").Window("Google").WebElement("html tag:=SPAN", "class:=radio-classic-ITEM-OFF", "text:=" & Parameter("Text")).Click

More QTP scripts here...

1 comment:

  1. What happend if i had Objekts with the same characteristics


Please leave your comment here...