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.

Check Checkbox in Web Page


Save the following HTML to a file called 'Test.html'
<html><title>Sample Checkboxes</title></head>
<body>
This will show how to manipulate checkboxes.... </p>
<P>
Checkbox 1 <input valign=top align=top type=checkbox name='CheckBox1'>
<P>
Checkbox 2 <input valign=top align=top type=checkbox name='CheckBox2'>
<P>
Checkbox 3 <input valign=top align=top type=checkbox name='CheckBox3'>
</body></html>

Save following script to a file called checkbox.wbt

#DefineSubRoutine startMSIE(url)
   objbrowser = ObjectCreate("InternetExplorer.Application")
   objbrowser.addressbar = @FALSE
   objbrowser.statusbar = @FALSE
   objbrowser.menubar = @FALSE
   objbrowser.toolbar = @FALSE
   objbrowser.visible = @TRUE
   objbrowser.navigate(url)
   ;   wait until page loads...
   WaitForPageLoad()
    ;   setup the document object...
   objbrowserdoc = objbrowser.Document
   Return(objbrowser)
#EndSubRoutine

#DefineSubRoutine WaitForPageLoad()  ; assume Browser
   While objbrowser.busy || objbrowser.readystate == 1
      TimeDelay(0.5)
   EndWhile
   While objbrowser.Document.ReadyState != "complete"
      TimeDelay(0.5)
   EndWhile
   Return
#EndSubRoutine

url = 'test.html'
startMSIE(url)

objelementcol = objbrowserdoc.GetElementsbyTagname("INPUT")
For e = 0 To objelementcol.length-1
   objelement = objelementcol.item(e)
   type = StrLower(objelement.type)
   If type == 'checkbox'
      checkboxname = objelement.name
      ischecked = objelement.checked
      If ischecked
         ret = AskYesNo(StrCat("Checkbox ",checkboxname, " is currently checked"),"Would you like to uncheck it?")
         If ret Then set = 0
         Else set = 1
      Else
         ret = AskYesNo(StrCat("Checkbox ",checkboxname, " is currently unchecked"),"Would you like to check it?")
         If ret Then set = 1
         Else set = 0
      EndIf
      objelement.checked = set
    EndIf
Next

objelement = 0
objbrowserdoc = 0
objbrowser = 0
Exit
Place the files in the same directory, then run check.wbt. You will be prompted each time a checkbox control is found on a webpage.
Article ID:   W17170
File Created: 2007:07:03:14:28:34
Last Updated: 2007:07:03:14:28:34