About Me

Gaurav Seth is a a Senior Automation Test Analyst with experience in QTP, Selenium and Ranorex tools and currently working on Automating in C# for a FX trading Client

Windows Scripting

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")
WshShell.AppActivate "Put the label of the browser" ' Activate the browser window
wait(3)
WshShell.SendKeys "^f" ' The caret (^) represents the CTRL key.
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.



' Below Piece of Snippet will Type in the notepad

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "Notepad"
WshShell.AppActivate "Notepad"
wait (3)
WshShell.SendKeys "x"

'Below Piece of code will open the Page Setup from the Notepad

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "Notepad"
WshShell.AppActivate "Notepad"
wait (3)
WshShell.SendKeys "%f"
WshShell.SendKeys "{Down}"
WshShell.SendKeys "{Down}"
WshShell.SendKeys "{Down}"
WshShell.SendKeys "{Down}"
WshShell.SendKeys "{Enter}"

No comments:

Post a Comment