Function to click on menu (Mimic the user action)

Share this post
FaceBook  Twitter  Mixx.mn     

To Navigate menu by using x & y cordinates i.e. mimicing user action, use following code
Steps:
1) Create Device Reply Object

2) Split Menu items .... Please note all menu items should be passed with a separator

3) For each menu items Identify menu item x and coordinate

4) Click on menu Item using device Replay .... Please note mouseDown is not released every time as when QTP take away mouse cursor then some times menu disappears

5) Once all menu is selected , Release mouse hold.
 

 Code:
'Function to click on menu (Mimic the user action)
'Menu_Item_Name= "Reports|Exception Report \(TO\)|Daily"

Function Menu_navigation(Menu_Item_Name)
'1) Create Device Reply Object
        Set DeviceReplay = CreateObject("Mercury.DeviceReplay")
        x=0
        y=0     
'2) Split Menu items .... Please note all menu items should be passed with a separator'        
        linkname= Split(Menu_Item_Name,"|")   

'3) For each menu items Idenify menu item x and coordinate       
        For i=0 to Ubound(linkname)
                Set linkobj=Browser("Home").Page("Document").Link("text:="& linkname(i) , "html tag:=A", "visible:=True")
                If linkobj.Exist Then
                        x=linkobj.getRoProperty("abs_x")
                        y= linkobj.getRoProperty("abs_y")
'4) Click on menu Item using device Replay .... Please note mouseDown is not released every time as when QTP take away mouse cursor then some times menu disappears                        
                        DeviceReplay.MouseUp  x, y,LEFT_MOUSE_BUTTON
                        DeviceReplay.MouseDown x, y,LEFT_MOUSE_BUTTON
                        wait 1
                        Reporter.ReportEvent micPass, "Click on Link", "Link " &  linkname(i) & " was Clicked successfully"
                Else
                        Reporter.ReportEvent micFail, "Click on Link", "Link " &  linkname(i) & " was not found"
                End If
        Next


'5) Once all menu is selected , Release mouse hold.        
        DeviceReplay.MouseUp  x, y,LEFT_MOUSE_BUTTON'
    Set DeviceReplay= nothing
End Function