Facebook

For any corporate training requirements Please mail To sudhakar@qtpsudhakar.com
New Schedule in MindQ Systems, Madhapur By SUDHAKAR
Course Name Date Time Duration Type Branch
UFT + UFTPro 20th September 2017 7.30 AM - 9.00 AM IST 25Days Classroom + Online Hitech City
Selenium+Appium 4th October 2017 4.30 PM - 6.00 PM IST 40Days Online -

A book "Cracking the QTP interview" authored by Sudhakar.Read More. Buy From FlipKart

Friday, March 26, 2010

Click on Object by Holding CTRL Key

We may get some situations to click on a link by holding CTRL Key. The normal click operation is not capable of doing that operation. It can click on the object using Left, Right and Middle Buttons of the mouse. Even the Sendkeys method of WSH cannot hold CTRL key.
The other option is Mercury Device Replay. The hidden object of the QTP. It is providing some methods to press and release a particular key of the key board. The below function will click on an object by holding CTRL key.

Function ClickObjectWithCtrlKey(Object)
 
'Declare Variables
Dim oDeviceReplay
Dim X_Axis
Dim Y_Axis
 
'Assign The CTRL key Index number to constant
Const VK_CONTROL = 29
 
'Check for object Existance
If Object.Exist(5) Then
 
' Create Device Replay Object
Set oDeviceReplay= CreateObject( "Mercury.DeviceReplay" )
 
'Press CTRL Key
oDeviceReplay.KeyDown VK_CONTROL
 
'Get X&Y axes of the object from application
X_Axis=Object.GetROProperty("abs_x")
Y_Axis=Object.GetROProperty("abs_y")
 
'Click on the object
oDeviceReplay.MouseClick X_Axis,Y_Axis,LEFT_MOUSE_BUTTON
'Release the CTRL Key
oDeviceReplay.KeyUp VK_CONTROL
 
End If
 
End Function
 
'Register the function to Link Class
RegisterUserFunc "Link","ClickObjectWithCtrlKey","ClickObjectWithCtrlKey"
'Call the function
Browser("Google").Page("Google").Link("Books").ClickObjectWithCtrlKey
'Unregister the Function
UnregisterUserFunc "Link","ClickObjectWithCtrlKey"

Note: Before executing this function the window/Browser of the object should be the first window of the desktop. This function works good in a continuation run. 
Click here to see the script for activating a opened window/browser.

3 comments :