The following HTML page will open an IE window, load a search page, wait for
it to finish loading, and then use SendKeys to perform a query at that
location (based on a passed search string).
It works.
However, I'm wondering if there is a better way to do the pause (Sub sSleep)
while waiting for IE to finish loading the page (this version uses PING to
insert a delay). Without it, IE complains that "A script on this page is
causing
Internet Explorer to run slowly ..."; and, WScript's Sleep method does not
seem to be available to IE.
TIA,
Bruce
<html><head><title>Page Search</title>
<script language="VBScript">
Dim sSearch
'remove leading "?" from search string
sSearch = Replace(window.location.search, "?", "")
'change URLEncoded "%20"s back to spaces
sSearch = Replace(sSearch, "%20", " ")
'open a new IE window and navigate to the search page
Dim oIE
Set oIE = createobject("internetexplorer.application")
oIE.navigate "http://somesearchpage.com/thesearchpage.asp"
oIE.Visible = True
'if there is a search string, do search
If Not window.location.search = "" Then
'wait til page is loaded
Do until oIE.readystate=4
sSleep 1
Loop
'enter the search criteria then ENTER
Dim oWSShell
Set oWSShell = CreateObject("WScript.Shell")
oWSShell.SendKeys sSearch
oWSShell.SendKeys "{ENTER}"
End If
'remove this window
window.close()
Sub sSleep(seconds)
'pause script about 1 second
Set oWSShell = CreateObject("Wscript.Shell")
cmd = "%COMSPEC% /c ping -n " & 1 + seconds & " 127.0.0.1>nul"
oWSShell.Run cmd,0,1
End Sub
</script>
</head><body></body></html>