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}"

Delete browser Cookies

We can use WebUtil.(Method)

webutil.DeleteCookie
or

webutil.DeleteCookies

Automating MS Word Documents

Following Snippet will inform you how to add a Text to the Tables in the Word document.

Set oWord = CreateObject("Word.Application")
oWord.Visible = True

Set oDoc = oWord.Documents.Add()
Set oRange = oDoc.Range()
oDoc.Tables.Add oRange,1,3
Set objTable = oDoc.Tables(1)
objTable.style = "Table Grid"

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Process")

nRow = 1
objTable.Cell(nRow, 1).Range.Font.Bold = True
objTable.Cell(nRow, 1).Range.Text = "Process"
objTable.Cell(nRow, 2).Range.Font.Bold = True
objTable.Cell(nRow, 2).Range.Text = "Description"
objTable.Cell(nRow, 3).Range.Font.Bold = True
objTable.Cell(nRow, 3).Range.Text = "Path"

For Each objItem in colItems

nRow = nRow + 1
objTable.Rows.Add()
objTable.Cell(nRow, 1).Range.Font.Bold = True
objTable.Cell(nRow, 1).Range.Text = objItem.Name
objTable.Cell(nRow, 2).Range.text = objItem.Description
If objItem.Executablepath <> "" then objTable.Cell(nRow, 3).Range.text = objItem.Executablepath
Next

QTP - Menu bar / Menu Items missing

To enable missing items or display all menu items in the menu bar, follow the following steps:-

1. Go to Start page of QTP
2. Go to Tools-->Options
3. In the general section, click on Restore Layout button.