Tuesday 19 July 2016

UFT/QTP using SendKeys option

When we are automating an application, sometimes objects may not be recognized. If we don't have any other option to recognize objects with QTP then we can chose option to take the keyboard control and automate the pending part.

Now a days, almost all applications are designed in such a way to follow W3C standards. For example, if we want to click on a button and currently cursor is focused on another object, we can use keyboard Tab option till that button focused. and then later we can hit on Enter button from keyboard to achieve our goal(clicking on button which is not recognized with QTP)

When this approach is recommended:
If we have automated almost 95%  of our script and only less then 5% steps are not able to automate because of objects not getting recognized then we can go ahead with keyboard sendkeys option.

To achieve this option we have a COM object available in VBScript.

Set objWshShell = WScript.CreateObject("WScript.Shell")

once above object is created then with this object
objWshShell.SendKeys "{TAB}"
objWshShell.SendKeys "{ENTER}"

Or

objWshShell.SendKeys "{TAB}~"

this will resolve above problem to click on button.

Below are few keystokes with equivalent to keyboard buttons available in VBScript

KeystrokeEquivalent
Alt%
Backspace{BACKSPACE}
Break{BREAK}
Caps Lock{CAPSLOCK}
Ctrl^
Delete{DELETE}
Down Arrow{DOWN}
End{END}
Esc{ESC}
Help{HELP}
Home{HOME}
Insert{INSERT}
Left Arrow{LEFT}
Num Lock{NUMLOCK}
Page Down{PGDN}
Page Up{PGUP}
Print Screen{PRTSC}
Right Arrow{RIGHT}
Scroll Lock{SCROLLOCK}
Shift+
Tab{TAB}
UP Arrow{UP}
F1{F1}
F2{F2}
F3{F3}
F4{F4}
F5{F5}
F6{F6}
F7{F7}
F8{F8}
F9{F9}
F10{F10}
F11{F11}
F12
{F12}

1 comment: