How to Fill a Web Form Using Sendkeys

How to Fill a Web Form Using Sendkeys thumbnail
Give your typing fingers a break by automating repetitive tasks.

Automation can save you time and keystrokes by making your computer operate itself. Sendkeys, a useful utility built into Windows, gives you the ability to experiment with real-time system automation. You can even use SendKeys to fill in Web forms automatically. Instead of typing in user IDs, address information and passwords, let your computer do the work. You don't need to be a programmer to create a simple script that works with any form you encounter on the Web.

Instructions

    • 1

      Launch a Web browser and navigate to a page that contains a form you would like to fill in. Press your "Tab" key repeatedly until the mouse cursor reaches the first text box on the form. Remember the number of key presses it takes to get to that text box.

    • 2

      Open Notepad or a text editor and paste the following code into a new document:

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

      The first line creates a Windows Script Host object. Windows Script Host allows you to communicate with Windows.

    • 3

      Add the line shown below after the one shown in the previous step:

      Shell.AppActivate("Windows Title")

      This code activates the Window that contains the title, "Windows Title." Replace "Windows Title" with the title that appears in your browser's Title bar.

    • 4

      Paste the following code below the code listed in the last step:

      Shell.SendKeys "{TAB}"

      This statement causes your computer to send at "Tab" key to the browser window. Duplicate this statement as many times as it took you to tab to the first field on the form. For example, if you had to tab three times, paste this code into the document:

      Shell.SendKeys "{TAB}"
      Shell.SendKeys "{TAB}"
      Shell.SendKeys "{TAB}"

    • 5

      Add the lines of code shown below after the code you created in the previous step:

      Shell.SendKeys "Text 1"
      Shell.SendKeys "{TAB}"

      Replace "Text 1" with the value you normally enter into the form. For instance, if it is a logon form, replace "Text 1" with you're the value that goes into the first text box. The second line tabs to the next text box.

    • 6

      Duplicate the previous two lines for each text box that exists on the form. If the form contains two more text boxes, add the following code after the code listed in the last step:

      Shell.SendKeys "Text 1"
      Shell.SendKeys "{TAB}"

      Shell.SendKeys "Text 1"
      Shell.SendKeys "{TAB}"

      After the computer tabs away from the final text box, it usually lies on the form's "Submit" button.

    • 7

      Paste this final statement after the code you created in the previous step:

      Shell.SendKeys "{ENTER}"

      This code sends an "Enter" key that presses the form's button. The following example shows how this document would look if it took you two tabs to arrive at the first text box in a form, and the form had two text boxes and a button:

      Set Shell = WScript.CreateObject("WScript.Shell")
      Shell.AppActivate("Title1")

      'Tab to first input field
      Shell.SendKeys "{TAB}"
      Shell.SendKeys "{TAB}"

      'Send Input
      Shell.SendKeys "Text 1"
      Shell.SendKeys "{TAB}"
      Shell.SendKeys "Text 2"
      Shell.SendKeys "{TAB}"

      'Tab to Submit button and press "Enter"
      Shell.SendKeys "{ENTER}"

      Save the document with a ".vbs" file extension. This creates a VBScript file.

    • 8

      Launch Windows Explorer and find that file. Navigate to the Web page that contains your form and double-click the VBScript file. Your browser moves to the foreground, and the script you created fills out the form and submits it.

Tips & Warnings

  • It is best to use a Web page's complete title in the Shell.AppActivate command, but it also works if you enter part of the title that appears in your browser window.

  • Once you create one VBScript program, you can modify it to work with other forms by adjusting the number of Tab key presses it takes to maneuver around that form.

  • Occasionally, it may take more than one Tab key press to jump from a form's final text field to the button that submits the form. If this situation exists, send additional Tab key presses using SendKeys as shown in the previous steps.

Related Searches:

References

Resources

  • Photo Credit Jupiterimages/Comstock/Getty Images

Comments

Related Ads

Featured