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.
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
Set WinShell = CreateObject("WScript.Shell") Setting.WebPackage("Replaytype")=2 Brower("ABC").Page("XYZ").WebList("FromPort").Click 'Click the weblist object to set focus on it Do WinShell.SendKeys "{DOWN}" 'Pressing Down Arrow 'Loop until required value is not selected Loop While Brower("ABC").Page("XYZ").WebList("FromPort").GetRoProperty("Selection") <> "Paris" Setting.WebPackage("Replaytype")=1 Set WinShell = Nothing |
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.
1 2 3 4 5 6 7 8 9 10 11 |
Set WinShell = CreateObject("WScript.Shell") Setting.WebPackage("Replaytype")=2 'Optional Brower("ABC").Page("XYZ").WebEdit("Name").Click 'Click the weblist object to set focus on it WinShell.SendKeys "John" Setting.WebPackage("Replaytype")=1 Set WinShell = Nothing |
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
- Settings.WebPackage Replaytype in UFT
- Find a Matching Pattern in String Using Regular Expression in UFT
- Descriptive Programming in UFT with Examples
- Micro Focus UFT Tutorial – An Overview of UFT
- DataTable in UFT One | Example of Datatable Methods
- Action Input And Output Parameters In UFT
- How to Use Recovery Scenario in UFT with Example
- File System Object UFT | VBA
- Read and Update XML File in UFT | VBA
- VBScript MySQL Database Connection in UFT
- VBScript Loops in UFT