Professional Documents
Culture Documents
application and then perform some operation like clicking that object or even right
clicking. I have created a short QTP tutorial for moving your mouse cursor on any
object in your application.
x=Browser("micclass:=Browser").Page("micclass:=Page").WebEdit("name:
=q").GetROProperty("abs_x")
y=Browser("micclass:=Browser").Page("micclass:=Page").WebEdit("name:
=q").GetROProperty("abs_y")
Set obj=CreateObject("Mercury.DeviceReplay")
obj.MouseMove x,y
Please make sure to resize your QTP window and your application before running
the above HP QTP script as shown below to see the effect:
As you have noticed, your mouse cursor has been shifted to the extreme left corner
of the search box. To place it somewhere in the middle, modify the fourth line in
the above script to:
obj.MouseMove x+10,y+10
The output after modifying the QTP script would be as shown below:
1. "abs_x" and "abs_y" are the object's absolute x and y coordinate relative to the
screen. Hence we are finding the extreme top-left coordinate of the search box
using the first two lines.
Just like we used MouseMove to shift my mouse cursor over the search box, we
can also simulate clicking on an object using MouseClick.
Hence, if we want to do a left mouse click inside Google search box, our QTP
script would be:
x=Browser("micclass:=Browser").Page("micclass:=Page").WebEdit("name:
=q").GetROProperty("abs_x")
y=Browser("micclass:=Browser").Page("micclass:=Page").WebEdit("name:
=q").GetROProperty("abs_y")
Set obj=CreateObject("Mercury.DeviceReplay")
obj.MouseClick x+10,y+10,0
And, if you want to do a right mouse click, replace the last line of above code with
the following:
obj.MouseClick x+10,y+10,2
Note: The above code will run successfully if you will resize your QTP window
while the script is running so that the search box is not hidden by the QTP window
while the script is running otherwise it may not work as desired.