Okey. Consider the below screen –
This is a Login dialog, contain few other object i.e. Agent name, password, buttons.
In this case Login Dialog is parent and Agent name, password, buttons are child objects.
How to use Childobjects method:
Suppose you have a page which gives you few options, i.e. Individual and Corporate. If you select 1st, on next page, you will see few fields like name, passport no, age, sex etc. But if you choose 2nd, you will see name, registration no, type of business etc.
Means page will be change on the basis of selection. Suppose you have 50 options, so you’ll be having 50 different pages, all with different number/type of objects. You don’t know how many objects will be there on any page.
Now you need to count the number of buttons on a particular screen, or, let’s say number of links on a web page. How to do that?
And the answer is.. using childobjects method!!
Open the above window – Start>>Program>>QuickTest ProfessionalSample Applicationsflight.exe>>Login into application, and run the following code in QTP..
Set oDesc=Description.Create()
Set oAll=Window(“text:=Flight Reservation”).ChildObjects(oDesc)
cnt=oAll.count
Print “Total number of objects: “&cnt
For i=0 to cnt-1
Print “Class: “&oAll(i).GetROproperty(“micclass”)&”, Text: “&oAll(i).GetROproperty(“text”)
Next
Above code will give you the number of objects on window. You can provide more specific description. Suppose you need to enter some value in all the textboxes on the page. You don’t know how many textboxes are there on page. Run following code..
Set oDesc=Description.Create()
oDesc(“micclass”).value=”WinEdit”
Set oAll=Window(“text:=Flight Reservation”).ChildObjects(oDesc)
cnt=oAll.count
Print “Total number of EditBox: “&cnt
For i=0 to cnt-1
If oAll(i).Getroproperty(“enabled”) Then
oAll(i).Set “Editbox:”&i
End If
Next
Here oAll is an array which contain all the textboxes and it’s index starts from zero. So if there are total 9 textboxes on window, array index will be oAll(0) to oAll(8).
Following is one more example. You have to click on particular button (if it displayed on the page). t might come or not..
Set oDesc=Description.Create()
oDesc(“micclass”).value=”WinButton”
Set oAll=Window(“text:=Flight Reservation”).ChildObjects(oDesc)
cnt=oAll.count
Print “Total number of Buttons: “&cnt
For i=0 to cnt-1
If oAll(i).Getroproperty(“text”)=”FLIGHT” Then
oAll(i).Click
End If
Next
I was working on a application, where you need to work on two instances of the application at the same time.(1st as customer and 2nd as trader). All properties are same because application is exactly same. In that type of situations, childobjects is the way you can survive upon!!
So it was starting learning advanced DP uses. Explore above codes and try to get good understanding of childobjects and getroproperty methods.
In next part of this post we’ll cover more advanced stuff of DP.
In case of any queries, please post your comments. Happy QTPing…!!
Jain Sahib, i really don't have any idea about QTP but there is a small observation:
in the very first example, you used oDesc in the second line but you didn't assign any property/value to this object. So, how it will work?
@Ankur
see these lines carefully..
Set oDesc=Description.Create()
Set oAll=Window("text:=Flight Reservation").ChildObjects(oDesc)
oDesc is just a blank object, which is passed to oAll. oAll will have all the objects.
hi ankur how to click one button among two or more buttons having same name
use child object..
Hi Abhikansh first i would like to thank u for ur posts, its very help full and clear, could u explain me the following statement how it works, GetROproperty is used to get the property of the object but why we are using it for the second time.
Print "Class: "&oAll(i).GetROproperty("micclass")&", Text: "&oAll(i).GetROproperty("text")
and why we are giving "k=i+2" in the first example in the for statement.
@kamalesh
thanks for your feedback.
GetROproperty is used two times for two different properties..
GetROproperty("micclass")
GetROproperty("text")
great article…recently joined a QTP project and this article is proving very instructive. Thanks a lot.
Hi Abhishek,
Thanks for posting this good article.My question is,suppose we have 6 Editbox with the same property on a page. I want to enter the data into the 4th box.I have some idea that index will be used in that case but how to write the code with that index. Could you please explain?
Akhilesh..may I know why what is purpose of using
GetROproperty("micclass")
Great post… Clears my doubts about child object method 🙂 Thank u.
Hi Abhi is it mandatory know the scripting for learning QTP. Because past 2+ years i am working as manual tester,so i am new to the tool. If VBS is mandatory which are the main key areas i have to concentrate. Please list out the topics.
@Bangalore
Can you Please share a complete example illustrating how to automate a page,,say irctc just show how to login ,search a train and click on book.Please show how to use wait statement also in this in this example
Also could you please explain what are the associated library functions in QTP and how to use it.
Thanks in advance !