Facebook

Course Name Start Date Time Duration Registration Link
No Training Programs Scheduled ClickHere to Contact
Please mail To sudhakar@qtpsudhakar.com to Register for any training

Wednesday, May 22, 2013

Diffrent ways to write a statement

'Different ways to write a statement

'##############################
'#### 1st method ###############
'##############################

'***Common Method***

'For Web

 Browser("Google").Page("Google").WebButton("Google Search").Click

'*******************

'For Windows

 Window("Flight Reservation").WinButton("Update Order").Click

'##############################
'#### 2nd method ###############
'##############################

'*** Assigning window object to an object variable***

'For Web

 'Assigning Parent Object to a variable
 Set oPageObj=Browser("Google").Page("Google")
 oPageObj.WebButton("Google Search").Click

 'Assigning Complete Object to a variable
 Set oBtnObj=Browser("Google").Page("Google").WebButton("Google Search")
 oBtn.Click
 
'*******************

'For Windows

 Set wndObject=Window("Flight Reservation")
 ' Following normal syntax ( click on a button)
 wndObject.WinButton("Update Order").Click

 '            OR

 ' Assigning Button object to an object variable
 Set btnObject=Window("Flight Reservation").WinButton("Update Order")
 ' Clicking on button using button object variable
 btnObject.Click

'##############################
'#### 3rd method ###############
'##############################

'*** Using With statement***

'For Web
  With Browser("Google").Page("Google")
   WebButton("Google Search").Click
  End With
  
'*******************

'For Windows

With Window("Flight Reservation")        
            .WinButton("Update Order").click
End with

'##############################
'#### 4th method ###############
'##############################

'***Descriptive programming (Static Description)***

'For Web

 Browser("name:=Google").Page("title:=Google").WebButton("name:=Google Search").Click

'*******************  

'For Windows

 Window("text:=Flight Reservation").WinButton("text:=&Update Order").Click

'##############################
'#### 5th method ###############
'##############################

'***Descriptive programming (Dynamic Description)***

'For Web

 Set oDes=Description.Create
 ' assigning description to the description object
 oDes("micclass").value="WebButton"
 oDes("name").value="Google Search"
 ' clicking on button using the created description object
 Browser("name:=Google").Page("title:=Google").WebButton(oDes).click

'*******************

'For Windows

 Set oDes=Description.Create
 ' assigning description to the description object
 oDes("nativeclass").value="Button"
 oDes("text").value="&Update Order"
 ' clicking on button using the created description object
 Window("text:=Flight Reservation").winbutton(oDes).click

'##############################
'#### 6th method ###############
'##############################

'***Using Descriptive Programming Child Object Method***

'For Web

 ' creating a description object
 Set oDes=Description.Create
 ' assigning description to the description object
 oDes("micclass").value="WebButton"
 
 ' Flitering the objects
 set btnObjList=Browser("name:=Google").Page("title:=Google").ChildObjects(oDes)

 For objIndex=0 to btnObjList.count-1
   ' Get property value from object
   propVal=btnObjList(objIndex).getroproperty("name")

   ' Compare property value
   If propVal="Google Search" Then
    ' Click on identified object
     btnObjList(objIndex).click
    ' Exit For loop after clicking on the button
     Exit for
   End If
 Next
 
'*******************

'For Windows

 ' creating a description object
 Set oDes=Description.Create
 oDes("nativeclass").value="Button"
 
 ' Flitering the objects
 set btnObjList=Window("text:=Flight Reservation").ChildObjects(oDes)

 For objIndex=0 to btnObjList.count-1
   ' Get property value from object
   propVal=btnObjList(objIndex).getroproperty("text")

   ' Compare property value
   If propVal="&Update Order" Then
    ' Click on identified object
     btnObjList(objIndex).click
    ' Exit For loop after clicking on the button
     Exit for
   End If
 Next

'##############################
'#### 7th method ###############
'##############################

'***By Storing Description in to Variable and replacing them with description***

'For Web

 ' Assigning Parent object description to constants
 Public const gBrowser="name:=Google"
 Public const gPage="title:=Google"
 
 ' Assigning Button object description to a constant
 Public const btnSearch="name:=Google Search"

 ' Click on a button using description constants
 Browser(gBrowser).Page(gPage).WebButton(btnSearch).Click

'*******************

'For Windows

 ' Assigning window object description to a constant
 Public const wndFlight="text:=Flight Reservation"
 ' Assigning Button object description to a constant
 Public const btnUpdate="text:=&Update Order"

 ' Click on a button using description constants
 Window(wndFlight).winbutton(btnUpdate).click

'##############################
'#### 8th method ###############
'##############################

'***By Using DOM Methods***

 ' Assigning Parent object description to constants
 Public const gBrowser="name:=Google"
 Public const gPage="title:=Google"

'Using GetElementsByName Method 
 'Get Elements List
 Set ElemLst=Browser(gBrowser).Page(gPage).object.getelementsbyname("Google Search")

 For each elem in ElemLst
  'Fliter Elements by Tag Name & Type
  If elem.tagName="INPUT" or elem.tagName="BUTTON" Then
   If lcase(elem.type)="button" Or lcase(elem.type)="submit" Then
    'Click on identified element
    Elem.click
   End If
  End If
  
 Next

'*******************

'Using GetElementById Method (For this method object must have Id)
 Browser(gBrowser).Page(gPage).object.getElementById("Google Search").click

'*******************

'Using GetElementsByTagName Method
 'If the button has input tag
 Set ElemLst=Browser(gBrowser).Page(gPage).object.getelementsbyTagName("INPUT")
        
    For each elem in ElemLst

        If elem.type="BUTTON" Or elem.type="SUBMIT" Then
            If elem.value="Google Search" Then
                elem.click
            Exit For
            End if
        End If
    Next

 'If the button has Button tag
 Set ElemLst=Browser(gBrowser).Page(gPage).object.getelementsbyTagName("BUTTON")
        
    For each elem in ElemLst
        If elem.type="BUTTON" Or elem.type="SUBMIT" Then
            If elem.value="Google Search" Then
                elem.click
            Exit For
            End if
        End If
    Next

No comments :

Post a Comment