1. Most objects support the TYPE method. Type will enter the specified string into an object or perform a certain keyboard combination against an application. For example:
To tab off an object you would use the following syntax:SwfObject(“swfname:=Blank”).Type micTab
To enter text:
SwfObject(“swfname:=Blank”).Type “This is my string”
To send an enter keystroke:
SwfObject(“swfname:=Blank”).Type “ “
You can also send a combination of keystrokes at one time. The following holds down the CTRL and the Shift Keys, then presses the “L” key and releases the CTRL and Shift keys:
SwfObject("swfname:=Blank").Type micCtrlDwn + micShiftDwn + "L" + micShiftUp + micCtrlUp
*Important to remember: If you send a down keystroke, be sure to follow it with its corresponding up stroke, as seen in the above example. Problems can arise by sending a micCtrlDwn and forgetting to release it using micCtrlUp. So, rule of thumb — if you are pressing a key, make sure to also release it.
2. VBScript SendKeys Method
There are instances in which QTP’s Type method does not trigger certain events, or is unable to mimic certain keystrokes. In these cases, VBScript SendKeys method can be used. To use the SendKeys you need to first set the WshShell object:Dim mySendKey
set mySendKey = CreateObject("WScript.shell")
mySendKeys.SendKeys(“{TAB}”)
To send the text you would use:
mySendKeys.SendKeys(“This is my string”)
To send an enter keystroke:
mySendKeys.SendKeys(“~”)
*A few important tips: Unlike the QTP TYPE method, you will need to use curly braces for arguments like a TAB or Up arrow key strokes. Also — SendKeys has the following special characters: Alt(%), Ctrl(^), Shift(+) and Enter(~) keys.
So, to send a CTRL and press the A key you would send:
mySendKey.SendKeys("^A")
If you need to perform the same keystroke multiple times, you can create a compound string argument. This will allow you to perform a specific keystroke and repeat it any number of times. To select, say, the 10th row in a grid control you might use:
mySendKey.SendKeys(“{DOWN 10}”)
This will send the down key ten times. (For a more detailed explanation of SendKeys check out VBScript Programmer’s Reference .)
Important – You’ll need to make sure that the application or object you wish to receive the keystroke has focus before sending the keystroke.
*Common issues with this method:
(Sometimes multiple keystrokes will not work. If this is the case, try executing each one in a separate line.)
3. Device Replay
This is an undocumented and unsupported QuickTest method, but can be used as a last resort. To employ this method, you’ll need to create a Device Replay object.To tab off an object:
Dim myDeviceReplay
Set myDeviceReplay = CreateObject(“Mercury.DeviceReplay”)
myDeviceReplay.PressKey 15
*Remember that Device Replay uses ASCII characters
To send text you would use:
myDeviceReplay.SendString “This is my string”
To send an enter keystroke:
myDeviceReplay.PressKey 28 ‘ASCII code for enter
From The HP knowledge base:
The
functions that can be used with the Device Replay object are (all
coordinates are relative to the top left corner of the screen):
|