Child Objects in QTP scripts with examples

Many at times in Scripting we come across scenarios where we need to count the objects in the application or even highlight a child object like highlighting a text box or check and uncheck check boxes using scripting in QTP.

Below are some of the examples where in you can do different actions. For our example we are using Flight Reservation application as reference.


'Script to count the number of child objects of flight reservation application
Set chd_obj = Dialog("text:=Login").ChildObjects
msgbox chd_obj.count

'Script to highlight all the child objects in Login dialog of flight reservation application
Set chd_obj = Dialog("text:=Login").ChildObjects
For i = 0 to chd_obj.count - 1
chd_obj(i).Highlight
Next

'Script to highlight all the child objects(buttons) in Login dialog of flight reservation application
Set button_obj = Description.Create
button_obj("nativeclass").Value = "Button"

Set chd_obj = Dialog("text:=Login").ChildObjects(button_obj)
For i = 0 to chd_obj.count - 1
chd_obj(i).Highlight
Next

'Script to check and uncheck all the check boxes in open order dialog box of flight reservation application
Set checkbox_obj = Description.Create
checkbox_obj("Class Name").value = "WinCheckBox"

Set chd_obj = Window("text:=Flight Reservation").Dialog("text:=Open Order").ChildObjects(checkbox_obj)
For i = 0 to chd_obj.Count - 1
chd_obj(i).Set "ON"
chd_obj(i).Set "OFF"
Next

4 comments:

Pooja said...

the example given here for checking and unchecking the checkboxes is giving an error:

The operation cannot be performed

Line (8): "chd_obj(i).Set "ON"".

Please suggest how to debug?

Kanikaram Kiranpaul said...

Will check and let you know

Unknown said...

On a webpage, I had to use:
checkbox(i).Set("ON")

Anonymous said...

Hi,

I am automating a .Net application using QTP11.
I am trying to ensure that a combobox is not empty and I can select a particular value from the combobox.
During runtime, the combobox is identified as SwfTree with SwfToolbar as parent. The recorded script is given below:
SwfWindow("mywindow").SwfToolbar("SwfToolbar").SwfTreeView("SwfTreeView").Select "Favourites;my fav".
When I rerun this recorded script, though the SwfTree and SwfToolbar are present in OR,it fails with below error:
"Can not find the "SwfTreeView" object's parent "SwfToolbar" (class SwfToolbar.

Could somebody please guide me on this?

Thank you

Post a Comment

/* Tynt Insight tracker ----------------------------------------------- */