Different Ways to click a button
Here i am giving an idea of how we can write the scripts in different ways..
Here i am taking an example in how many ways we can write a statement to click on a specified button.
I took two conditions first one is when we are using object repository, second one is when we are not using object repository
(Using Descriptive programming) .
Using Object Repository
'1st method
Window("Flight Reservation" ).WinButton( "Update Order").Click 'Common Method
'2nd method
Set wndObject=Window( "Flight Reservation" ) ' Assigning window object to an object variable
wndObject.WinButton ("Update Order").Click ' Following normal syntax ( click on a button)
' OR
Set btnObject=Window( "Flight Reservation" ).WinButton( "Update Order") ' Assigning Button object to an object variable
btnObject.Click ' Clicking on button using button object variable
'3rd method
With Window("Flight Reservation" ) ' Using With statement
.WinButton(" Update Order").click
End with
Using Descriptive Programming
'4th method
Window("text: =Flight Reservation" ).WinButton( "text:=&Update Order").Click ' Descriptive programming
'5th method
Set oDes=Description. Create ' creating a description object
oDes("nativeclass" ).value=" Button" ' assigning description to the description object
oDes("text") .value="&Update Order"
Window("text: =Flight Reservation" ).winbutton( oDes).click ' clicking on button using the created description object
'6th method
Set oDes=Description. Create ' creating a description object
set btnObjList=Window( "text:=Flight Reservation" ).ChildObjects( oDes) ' Flitering the objects
For objIndex=0 to btnObjList.count- 1
propVal=btnObjList( objIndex) .getroproperty( "text") ' Get property value from object
If propVal="&Update Order" Then ' Compare property value
btnObjList(objIndex ).click ' Click on identified object
Exit for ' Exit For loop after clicking on the button
End If
Next
'7th method
Public const wndFlight="text: =Flight Reservation" ' Assigning window object description to a constant
Public const btnUpdate="text: =&Update Order" ' Assigning Button object description to a constant
Window(wndFlight) .winbutton( btnUpdate) .click ' Click on a button using description constants
You need to be a member of QTPPro to add comments!