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.

Set Focus on HTML Form Control


Sets focus on the first Editbox control on a the form.
#DefineSubRoutine startMSIE(url)
   Browser = ObjectOpen("InternetExplorer.Application")
   Browser.addressbar = @FALSE
   Browser.statusbar = @FALSE
   Browser.menubar = @FALSE
   Browser.toolbar = @FALSE
   browser.visible = @TRUE
   browser.navigate(url)
   ; wait until page loads...
   WaitForPageLoad()
   ; setup the document object...
   browserDoc = Browser.Document
   all = browserdoc.all
   Return(browser)
#EndSubRoutine

#DefineSubroutine WaitForPageLoad()  ; assume Browser
   While browser.busy || browser.readystate == 1
      TimeDelay(0.5)
   EndWhile
   While browser.Document.ReadyState != "complete"
      TimeDelay(0.5)
   EndWhile
   return
#EndSubroutine




url = "https://commerce.windowware.com/webcgi/webbatch.exe?updates/update.web"      ;<-- change to the web http://whatever.com...
br  = startMSIE(url)

browserdoc = br.Document


;      retrieve
InputList = browserdoc.GetElementsByTagName("INPUT")

; zero-based collection...first editbox is second form control
MyEditBox = InputList.item(1)

MyEditBox.focus()

ObjectClose(MyEditBox)
ObjectClose(InputList)


Exit




;   okay start MSIE by hand and then navigate to your web page.
;   if you have other MSIE windows open, close them.

;   then run this script. it will attach to the existing page,
;   then access the document, and the controls scroll the 2nd checkbox
;   into view and even check the check box to prove it.

tablename = "MsgTable"   ;!!!!!!!!! CHANGE TO FIT YOUR NEEDS!!!!!!!

;Check to see if ClassID installed
myShellWindowsClsid="{9BA05972-F6A8-11CF-A442-00A0C90A8F39}" ;ShellWindows
myShellWindowsKey="AAA.TEST\CLSID"
If RegExistValue(@REGCLASSES,myShellWindowsKey) == @FALSE
   RegSetValue(@REGCLASSES,myShellWindowsKey,myShellWindowsClsid)
   If RegExistValue(@REGCLASSES,myShellWindowsKey) == @FALSE
      Message("CLSID Not installed.","Need Admin access")
      Exit
   EndIf
EndIf

;   attach to the open explorer windows including MSIE...

SWs=ObjectAccess("AAA.TEST",1)
count=Sws.count
Message("Count",count)

For xx=0 To count-1
   windowobject=Sws.Item(xx)
   lu = windowobject.LocationURL
;   message("Debug", strcat(windowobject.name, @crlf, windowobject.fullname))
   If StrIndexNC(windowobject.fullname, "iexplore.exe", 1, @FWDSCAN) > 0         ; <--- only grab MSIE windows
      browserdoc = windowobject.document
      GoSub SetFocus
      Break
   EndIf
Next

Exit

:SetFocus
all = browserdoc.all

;reference the Table...
Table = all.%tablename%
;      retrieve the collection of INPUTs within the MsgTable...
InputList = Table.GetElementsByTagName("INPUT")

MyCheckBox = InputList.item(1)            ;   the first message is index 1 (the 2nd) of the zero-based collection...
MyCheckBox.focus()                        ;  set the focus...

Message("Debug", "The 2nd checkbox should be in view...")

If AskYesNo("MSIE", "Do you want the 2nd checkbox checked?") Then MyCheckBox.checked = 1

ObjectClose(MyCheckBox)
ObjectClose(InputList)
ObjectClose(Table)
Return



Article ID:   W16640
File Created: 2005:02:18:12:21:42
Last Updated: 2005:02:18:12:21:42