There are occasions when keyboard inputs are not recorded or replayed successfully using the normal recording methods of UFT One (QTP). Also many applications depend on keyboard events to trigger the opening of a window/pop-up window or displaying an edit field. To send keyboard inputs to an application using QTP we have many ways. I suggest using them in the order in which they appear below. (I prefer using low-level recording or analog recording recording as the last option in QTP.
1. Use the simplest .Type ( key ) to send keyboard input.
Eg:
Window("Notepad").WinEditor("Edit").Type micF5
2. Use the Windows Scripting SendKeys method
There are some Web/Windows objects which will perform actions when certain key commands, such as CTRL+SHIFT+ESC
are entered. These Web/Windows objects do not have a type method associated with them that can be used to replay these keys. In these cases you can use SendKeys
method to send keyboard input to your application.
Download and install the Windows Scripting Host.
1. Create a WScript.Shell
object.
2. Activate the browser in which you want to execute the keys.
3. Use the SendKeys
method to type the key combination.
Example:
'This code executes the CTRL+F key combination (search) on a browser. Set WshShell = CreateObject("WScript.Shell") 'Activate the browser window WshShell.AppActivate "Put the label of the browser" wait(3) 'The caret (^) represents the CTRL key. WshShell.SendKeys "^f" wait(2)
The SendKeys
method will send keystroke(s) to the active window. To send a single character (for example, x), use “x” as the string argument. To send multiple characters (for example, abc), use “abc” as the string argument. You can also send special characters such as SHIFT, CTRL, and ALT, which are represented by the plus sign (+), the caret (^), and the percent sign (%), respectively.
For more information on the SendKeys
method, please refer to the MSDN SendKeys Method page.
3. Use Analog or low-level recording when entering keyboard input
4. Use Mercury Device Replay feature
The Device Replay feature is used to perform mouse and keyboard actions against screen co-ordinates that are provided. The Device Replay functions are not automatically recorded, but must be programmed manually in the Editor/Expert View.
1. Creating the Device Replay Object.
2. Calling the Device Replay function.
3. Destroying Device Replay object.
Here is an example to simulate F5 function key using DeviceReplay
.
Set obj = CreateObject("Mercury.DeviceReplay") Window("Notepad").Activate obj.PressKey 63
The PressKey
method uses the appropriate IBM Scan Code value for the key. “63” is the IBM Scan Code value for F5.
For more information on IBM Scan Codes, refer to Lookup Tables. Click the “Scan Codes & EBCDIC” tab. The value needed for the PressKey
method is the decimal value.
Hey Ankur
Can you please tell me what can I do when qtp is not recording keystrokes from keyboard while recording windows application
Hi,Can Some one help me in writing QTp script test applications using “RunAs” command
QTP Script test applications using “RunAs” command In IE browser,Can please some Help
I am trying to trigger the “Enter” key on the keyboard after inputting a number into an input field. No matter what method I try It won’t work. Can you explain how to trigger the pressing of an “Enter” key please?
In my application weblists are identified as webedits.
Also If I click manually the link is working, if I run the qtp script I am not able to click on it and i got error message as “Object is disable”. Could you help me Please
Thanks!!
Hi ankur,
I am trying to automate the outlook 2010, the problem persists as eac objects ont he left hand side of the outlook are identifiable as winobject with each and every property are same. kindly suggest as i tried device replay method and replay type too click on the object.
can i use descriptive programming?if yes then please suggest few methods as all the objects and its properties are same.
Regards
Prachi
code to perform keybord enter operation from qtp
Hi Ankur, Need your favour in recognizing Fn key of may laptop by QTP. I have searched everywhere but couldnot get how QTP will recognize this key.
I am trying to take a screenshot in my laptop, that can be done using Fn key, using {PRTSCN} does not help.
If you could help me please ??
Regards,
Hemant Madan
In order to take screenshot of the running application, type the application name with property captureBitmap.
E.g. To take screenshot of the Browser having google opened;
Browser(“Mozilla”).Page(“Google”).captureBitmap
Ankur,
In my application buttons are identifying as links and weblists are as webedits.
Also If I click manually the link is working, if I run the script I was able to click but the data is not saving. Please advice.
Thanks!!
Hi Ankur, I did not find the scan code for shift key and also leftarrow doesnot work for me with devicereplay. it types 4.
Hi, Guys
Can any one tell me how can we automate DOS-PROMPT using QTP.
Hi ankuar,
I am unable to perform click operation in gmail on webelements….
i am able to saw teh result as click operation performed but operation is not happening in IE..
my code is :
i am tring to delete the all mails in Trash
Browser(“title:=Gmail.*”).Page(“title:=Gmail.*”).WebElement(“innertext:=All”, “Index:=*.*”,”html tag:=SPAN”).Click(Working fine)
Browser(“title:=Gmail.*”).Page(“title:=Gmail.*”).WebElement(“innertext:=Delete forever”,”index:=*.*”, “html tag:=DIV”).Click(in th etest results i am seeing click operation is done but delete operation is not performed)
kindly pls help me..
In the same way i tried to click some other webelements (buttons) ..but they are also not working..Ex: Search Mail
Hi,
I want to perform a Keyboard action – Press 2 keys at one instance, as in CTRL+Q.
Plese advise on how to perform this action using a VB-Script in QTP.
Regards,
Baibhav.
Hi Ankur,
First i am thanful to u for the blog,which is i found realy very helpful.
i faced a question that how u will enter a value in a webedit box without using .set method in qtp?
still this is unsolved for me.
Thanx in advance
Alok
if any one know how to scroll the web page by qtp script, please post with suggestions
Hey Ankur,
i am raj, this is a great help for me.
can you help me how to work on unix and linux through QTP9.5.
how to write qtp script on Linux and unix environment.
Please help.
Provide some sample QTP script which is developed in Unix and linux.
Thanks,
Raj.
hey ankur,
im abi, u did a great job can you help me how to write scripts frm QTP 9.2 give me some samples…
im very new from this projects…
Hey Ankur,
gr8 work. Its helping me a lot in my daily routine. Thank u very much……
hi ankur,
when i try to download some file and try to record this action,it does get recorded but when i try to run the action it gives an error as(can’t find the parent object) can u help me out to fix this problem