Monday, July 22, 2013

VB Script to Automate Internet Explorer without using any tool

In this post i will describe you how vb script can be used for automating internet explorer without using any tool.
The below mentioned text will open internet explorer and then google page put some text in the Text box.

Steps to follow:

Step 1:Open the notepad file

Step 2:Copy the below mentioned code and save the file with the .vbs extension.

Option Explicit

strText = "My VB Script"  'Enter some sample  Text over here.


Dim objLink , ie , WshShell , colLinks
Dim i , intDay , intOff , intcount , btn, strText, j
Dim strUser , strPwd , hwnd, Wnd, oShell, objImage, objImages , strOut

Sub WaitForLoad(obj)
   Do While ie.Busy
   Loop
 
   Do While obj.readyState <> 4
   Loop
   wscript.sleep(100)
End Sub

'Create ie and shell object
Set ie = WScript.CreateObject("InternetExplorer.Application")

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

'set the ie properties whichever you want that your internet explorer should contain.
ie.ToolBar = 1
ie.StatusBar = 1
ie.Width = 1500
ie.Height = 999
ie.Left = 0
ie.Top = 0
ie.Visible = 1

With ie
hwnd = .hwnd
      .Navigate "http://google.com"  'Enter URL  here that you want to work on.
End With

Set oShell = CreateObject("Shell.Application")
For Each Wnd In oShell.Windows
        If hwnd = Wnd.hwnd Then Set ie = Wnd
Next

'wait until the page has loaded before continuing

WaitForLoad(ie)

'Enter the user details

ie.Document.getElementByID("gbqfq").Value = strText 'Inspect it by using any inspect tool that you have.
WaitForLoad(ie)

No comments:

Post a Comment