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>

Re: sleep, wait, or pause in HTML page by mr

mr
Mon Sep 13 15:41:44 CDT 2004

hi Bruce,

this is a "frequently-asked-question" here, and NO, there is no wait, sleep,
etc. in vbs hosted by IE.

If you google the scripting groups, you will find some suggested
work-arounds, but the most straight-forward approach is to just set a timer.

the timer will wake you up periodically. Test if the event has occurred
that you are waiting for (page loaded). Then simply continue with what you
wanted your script to accomplish.

cheers, jw

"Bruce Hensley" <nobody@nowhere> wrote in message
news:OVxRizbmEHA.3372@TK2MSFTNGP15.phx.gbl...

> 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



Re: sleep, wait, or pause in HTML page by Michael

Michael
Mon Sep 13 19:06:27 CDT 2004

(multipost) answered in ...scripting.wsh


--
Michael Harris
Microsoft.MVP.Scripting
Sammamish WA US