WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with MSIE
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Automate Input into Form using COM / OLE

Keywords:  OLE Forms Input

This code shows you how to automate data input in an Internet Explorer form with WBT script. It read the field values and then writes the data into the fields of a form.

First the Form:

<html><head><title>Test</title>
    </head><body>
    <p align="center"><big><strong>Test with IE and WB</strong></big></p>
    <form name="frmTest">
      <p><span name="lblTest" id="lblTest">Label</span></p>
      <p>Field: <input name="txtTest" type="text" size="20"></p>
      <p>Text: <textarea name="edtTest" rows="2" cols="20"></textarea></p>
      <p><input name="chkTest" type="checkbox" value="ON" id="fp1"><label for="fp1" accesskey="C"><U>C</U>heck</label></p>
      <p>
        <input name="opgTest" type="radio" value="1" checked>RadioButton 1<br>
        <input name="opgTest" type="radio" value="2">RadioButton 2
      </p>
      <p>
        <select name="cboTest" size="1">
          <option value="Combobox 1">Combobox 1</option>
          <option value="Combobox 2">Combobox 2</option>
          <option value="Combobox 3">Combobox 3</option>
          <option value="Combobox 4">Combobox 4</option>
        </select>
      </p>
      <p>
        <input type="button" value="View" name="cmdView"> 
        <input type="submit" value="Enviar" name="B1">
      </p>
    </form>
    </body></html>

    

Next the WBT File:

;-------------------------------------------------------------------------
    ;--     Program : IETest.WBT
    ;-- Description : Write values and submit a HTML Form with WB OLE and IE
    ;--  Parameters : -
    ;--       Notes : Need Internet Explore 4.x
    ;--
    ;-------------------------------------------------------------------------

    ;-- Open Internet Explorer
    oIExplorer = ObjectOpen("InternetExplorer.Application")
    oIExplorer.Visible = @TRUE
    ;-- Goto the HTML form
    cPath = DirScript()
    oIExplorer.Navigate(StrCat("file://",cPath,"IETest.htm"))
    ;-- Wait
    While oIExplorer.Busy==1 || oIExplorer.ReadyState == 1
       TimeDelay(0.5)
    EndWhile


    ;-- Write in HTLM form elements
    myDoc = oIExplorer.Document      ;Get Document Object
    ;-- TEXTBOX
    txtAll = myDoc.All("txtTest")   ;Get all Objects with the name txtTest
    txtAll.value = "Hello"          ;Write value
    ;;-- EDITBOX
    myfrmTest = myDoc.frmTest         ;Get Form Object
    myedtTest = myfrmTest.edtTest   ;Get Editbox Object using name
    myfrmValue = myedtTest.value    ;Read value
    myedtTest.Value= "Hello"        ;Write value
    ;-- CHECKBOX
    myChkTest = myfrmTest.chkTest   ;Get Checkbox Object
    myChecked = myChkTest.Checked    ;Read value
    myChkTest.checked = @TRUE         ;Write value
    ;-- SELECT
    mycboTest = myfrmTest.cboTest    ;Get Combobox Object
    mycboValue = mycboTest.value    ;Read value
    mycboTest.Value = "Combobox 3" ;Select value
    ;-- RADIO
    myopgTest = myfrmTest.opgTest(1);Get Second Radiobutton Object
    myopgChecked = myopgTest.Checked ;Read value
    myopgTest.Checked = @TRUE      ;Select value

    ;Close Objects
    myopgTest = 0
    mycboTest = 0
    myChkTest = 0
    myedtTest = 0
    myfrmTest = 0
    txtAll = 0
    myDoc = 0
    oIExplorer = 0


    ;-----------------------
    ;-- End of IETEST.WBT --
    ;-----------------------

Here's the original VBS File for Reference:

    On Error Resume Next
     
    '-- Open Internet Explorer
    Set oIExplorer = CreateObject("InternetExplorer.Application")
    oIExplorer.Visible = True
    '-- Goto the HTML form 
    cPath = Replace( Wscript.ScriptFullName, WScript.ScriptName, "" )
    oIExplorer.Navigate( "file://" & cPath & "IETest.htm" )
    '-- Wait
    Do While oIExplorer.Busy or oIExplorer.ReadyState = 1
    Loop
     
    '-- Write in HTLM form elements
    '-- LABEL (need a SPAN with ID for this element)
    oIExplorer.Document.all("lblTest").innerText = "Hello"
    '-- TEXTBOX
    oIExplorer.Document.All("txtTest").value = "Hello"
    '-- EDITBOX
    oIExplorer.Document.frmTest.edtTest.value = "Hello"
    '-- CHECKBOX
    oIExplorer.Document.frmTest.chkTest.checked = True
    '-- SELECT 
    oIExplorer.Document.frmTest.cboTest.value = "Combobox 3"
    '-- RADIO
    oIExplorer.document.frmTest.opgTest(1).checked = True
    
    '-- Events
    '-- CLICK
    oIExplorer.document.frmTest.cmdView.Click()
    '-- SUBMIT
    oIExplorer.document.frmTest.submit()
     
    '-- Wait for sumit action
    Do While oIExplorer.Busy or oIExplorer.ReadyState = 1
    Loop
     
    
    '-----------------------
    '-- End of IETEST.VBS --
    '-----------------------
    
  

Article ID:   W14390
Filename:   Automate Input into Form with IE4.txt
File Created: 2011:09:06:09:47:46
Last Updated: 2011:09:06:09:47:46