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.

Setting Focus on an HTML Control


This will illustrate how to check for the active element on an HTML page, using Winbatch and OLE.

If you're not starting the browser thru OLE then you'll have other issues to contend with, like attaching to an instance of the browser, finding the correct one and then performing the lookups of the objects. Search thru the TECH DATA BASE for "AAA.Test"

It's much easier if you make the document and give each control distinct IDs.

Winbatch 2004F and MSIE 6...by Jay Alverson

#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


;
;   setup the page for the browser...
HTML = `You can click with the mouse or use the TAB key...<br><br>`
HTML = StrCat(HTML, `<table width="550" border=1 style="border-collapse: collapse">`, @CRLF)
HTML = StrCat(HTML, `<caption><th colspan=2>Check Boxes</th></caption>`, @CRLF)
;   place 10 checkboxes inside the table, each with a unique ID...
For x = 1 To 10
   If x < 10 Then x = StrCat("0",x)
   HTML = StrCat(HTML, `<tr><td>Check Box # %x%<input type="checkbox" id="Checkbox%x%"></td><td><input type="checkbox" id="Checkbox%x%"></td></tr>`, @CRLF)
Next
HTML = StrCat(HTML, `</table>`, @CRLF)
;   setup a span to hold the contents of the current active element...
HTML = StrCat(HTML, `<br><br>Current Focus: <span id=FocusSpan></span>`, @CRLF)
;   and an exit button for when the script is done...note the ONCLICK attribute...
HTML = StrCat(HTML, `<br><br><input type=button id=ExitButton value="Exit Script" onclick="FocusSpan.innerText='Exit'">`, @CRLF)
;
;   setup the URL for a blank document...
url = "about:blank"
;   start the browser and navigate to the blank document...
br = startMSIE(url)
;
;   write the HTML to the document...
browserdoc.writeln(HTML)
;   setup a reference to the focus span, which will hold the ID of the active element...
FocusSpan = all.FocusSpan
;
;   loop until the exit button is pushed...
While @TRUE
   Yields(2000)
   If FocusSpan.innerText == "Exit" Then Break ;<-- exit when the button is clicked...
   active = browserdoc.activeElement  ;<-- otherwise always get the current active element
   FocusSpan.innerHTML = StrCat(`<font color=red><b>`, active.id, `</b></font>`)   ;<-- and place the id into the span...
   ObjectClose(active)
EndWhile

br.quit

Exit


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