For any corporate training requirements Please mail To sudhakar@qtpsudhakar.com
Course Name Date Time Duration Type Location
An important update from QtpSudhakar. I stopped giving classroom training in MindQ Systems. I have bigger plans and I want to put an end to regular classroom training because very less people are practicing. From now onwards every session of mine is going to have explanation and practice. Everyone should practice in presence of mine and should go out of classroom with practical knowledge. So I started my own institute AnyTechLabs in Madhapur. Please reach out to +91-8328152362 for course details. Visit AnyTechLabs.com for address details.
Selenium + Cucumber 24th October 7.30 AM IST to 9.00 AM IST 45 Days WeekDay 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
'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
'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.