How to Use Shell Scripting in UFT to SendKeys

Shell Scripting in UFT is used sendkeys (simulate keyboard key press) to tackle a few very uncommon behavior of some test applications. Sometimes we come across a few rare scenarios wherein UFT can’t perform a select operation in a list box, set a text in the text box, or click a button even though UFT is able to identify the object. This is a very rare phenomena that may happen with complex web applications.

Shell Scripting SendKeys in uft

Consider an example wherein UFT can identify a WebList object but if you record the action of selecting an item from the drop-down, the particular step does not get recorded. Even if you manually write the code for selecting a required item from a Weblist, UFT does not select the required item at runtime. It’s a bizarre scenario that happens very rarely with few Weblist objects of a complex application. Sometimes the same kind of issues come up with TextBox object. If you come across such a situation for the first time you might get stuck. In such a situation shell scripting acts as a savior and the issue can easily be figured out using Shell scripting. In this article, I have given examples of selecting a value from a dropdown and setting text in a text box. I have also used the ReplayType in this example. Without this sometimes things don’t work out. To know more about ReplayType please refer to my post Settings.WebPackage Replaytype in UFT.

Select a Value From a Drop-down Using Shell Scripting in UFT

If you know the index of the required value in the dropdown you can simply send DOWN arrow keys as many times until the required value is selected and then send the ENTER key. In this case, looping is not required.

Set a Value in a Textbox Using Shell Scripting

You can use the following code to set a value in a text box using shell scripting. Before using the following code make sure the cursor is pointing to the required TextBox object. If the cursor is not pointing to the required TextBox, you can also send TAB keys using shell scripting after creating the windows shell object and use the code WinShell.SendKeys(“{TAB}”) to send the TAB key.

The following table has the Key and Code name that can be used to sendkeys in UFT on a desired Test Application object.

Key Code
BACKSPACE {BACKSPACE} or {BS}
BREAK {BREAK}
CAPS LOCK {CAPSLOCK}
CLEAR {CLEAR}
DELETE or DEL {DELETE} or {DEL}
DOWN ARROW {DOWN}
END {END}
ENTER (numeric keypad) {ENTER}
ENTER ~
ESC {ESCAPE} or {ESC}
HELP {HELP}
HOME {HOME}
INS {INSERT}
LEFT ARROW {LEFT}
NUM LOCK {NUMLOCK}
PAGE DOWN {PGDN}
PAGE UP {PGUP}
RETURN {RETURN}
RIGHT ARROW {RIGHT}
SCROLL LOCK {SCROLLLOCK}
TAB {TAB}
UP ARROW {UP}
F1 through F15 {F1} through {F15}

You can also send a combination of keys with SHIFT and/or CTRL and/or ALT. Refer to the following table to send a key combined with another key or keys.

Key Code
SHIFT
CTRL
ALT

Example

You can close a notepad or any file by sending Alt+f+x key.

WinShellObj.SendKeys “%fx”

Recommended Posts

Leave a Reply