Tuesday, April 14, 2015

Right click on a weblink using QTP

'The below scripts selects the second pop up item after right clicking on the weblink.

'Open the Yahoo website in IE and execute the script.
'Opens the images webpage(open in new tab) in a new tab

Setting.WebPackage("ReplayType") = 2
'This statement makes the replay type to Mouse from event. Without this configuration the script may or may not work.

Set link=browser("Yahoo!").Page("Yahoo!").Link("Images")
link.highlight
index=2
Set obj = CreateObject("Mercury.DeviceReplay")
Set WshShell = CreateObject("WScript.Shell")

'Get the absolute coordinates of the object
absx = link.GetROProperty("abs_x")
absy = link.GetROProperty("abs_y")

'Right click on the Object
obj.MouseClick absx+5, absy+5, 2 'Here 2 is for right click

'Optional wait statement
wait 2

'Clicking number of downs
For i = 1 To index
WshShell.sendkeys "{DOWN}"
Next

WshShell.sendkeys "{ENTER}"

Setting.WebPackage("ReplayType") = 1

Set WshSEll = nothing
Set obj = nothing