For any corporate training requirements Please mail To sudhakar@qtpsudhakar.com
Course Name Date Time Duration Type Location
WhatsApp to 91-8328152362 for address details of AnyTechLabs
Selenium + Appium 27th February 2019 7.00 AM IST to 8:45 AM IST 45 Days Class Room + Online AnyTechLabs
Selenium + Appium 9th March 2019 9.00 AM IST to 2.00 PM IST 5 WeekEnds Class Room + Online AnyTechLabs

A book "Cracking the QTP interview" authored by Sudhakar.Read More. Buy From FlipKart

Tuesday, September 15, 2009

Object Hierarchies in QTP

Is it Mandatory to Follow Object Hierarchies Specified by QTP?

We all know that the basic object hierarchy specified by QTP is from parent to child. If is there multiple parent hierarchies then we have to start from higher level parent.


1. Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click 
2. Browser("Browser").Dialog("Internet Security Alert").WinButton("Yes").Click 

But we don't need to follow the basic hierarchy in this case. We can ignore the top level parent object to work with Dialogs.

Using the below code you can directly work with Objects in Dialog.

'Using the Function
Set oObjDescription=CreateObjectDescription("text:=OK")
set oObject=GetDialogObject("Open Order",oObjDescription)


Function GetDialogObject(oDialogTitle,oObjProperties)

Dim oDialog
Dim iIndex
Dim oDialogName
Dim oDialogObjects

Set oDialogDescription=Description.Create

Set oDialogObjects=Desktop.ChildObjects(oDialogDescription)

If  oDialogObjects.count=1 Then

For iIndex=0 to oDialogObjects.count-1
If  trim(lcase(oDialogName))=trim(lcase(oDialogTitle)) Then
Set oDialogChildCollection=oDialogObjects(iIndex).ChildObjects(oObjProperties)
If  oDialogChildCollection.count=1 Then
Set GetDialogObject=oDialogChildCollection(0)
elseIf  oDialogChildCollection.count>1 Then
msgbox "More Objects Found With Provided Properties"
ElseIf  oDialogChildCollection.count=0 Then
msgbox "No Object Found With Provided Properties"
End If
Exit For
End If
ElseIf  oDialogObjects.count>1 Then
msgbox "More Objects Found With Provided Properties"
ElseIf  oDialogObjects.count=0 Then
msgbox "No Object Found With Provided Properties"
End If

Set oDialog = Nothing
Set oDialogObjects = Nothing
Set oDialogChildCollection = Nothing

End Function

Function CreateObjectDescription(StrProperties)

Dim objDescription
Dim ObjArr
Dim PropCount
Dim ObjProperty

Set objDescription=Description.Create


For PropCount=0 to ubound(ObjArr)

Set CreateObjectDescription=objDescription

End Function


For Web Applications we follow the hierarchy like this

Browser("browser").Page("page").WebEdit("edit").Set "Sudhakar Kakunuri"

The same statement will work without page object.


Browser("browser").WebEdit("edit").Set "Sudhakar Kakunuri"

Please send your Suggestions, Doubts about my blog and posts to my yahoo group http://in.groups.yahoo.com/group/qtpsudhakar

No comments :

Post a Comment