sleep, wait, or pause in HTML page

From: Bruce Hensley (nobody_at_nowhere)
Date: 09/13/04


Date: Mon, 13 Sep 2004 11:09:58 -0700

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>



Relevant Pages

  • Returning selected items in an open folder
    ... items in an open folder window. ... Dim boo As Boolean ... '-- s1 is a unique string that's part of a specific open folder path. ... Private Sub Form_QueryUnload ...
    (microsoft.public.vb.general.discussion)
  • Slow Soft-RAID 5 performance
    ... The Kernel boot log is attached as boot.msg ... MEM window: disabled. ... registered new interface driver usbfs ... Loading ide-core ...
    (Linux-Kernel)
  • Re: Are VBA userforms always child of Windows desktop?
    ... Private Declare Function GetDesktopWindow Lib "user32" As Long ... Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long ... The system restores the window to its original state. ... Dim hWndDesktop As Long ...
    (microsoft.public.excel.programming)
  • Re: ShellExecuteEx and Information about remote application
    ... Determine when video file has been closed (when user ... Shell" and have tried to retreive the hWnd of the new video window. ... Dim ShellEI As SHELLEXECUTEINFO ... Dim hWndChild As Long ...
    (microsoft.public.vb.winapi)
  • Re: Why doesnt this recursive function return the right value?
    ... Simply the ByRef nHold arg works fine, though of course the function may not ... of nTmp & nResult and don't rely on the function returning a value. ... >> Dim x As Long, ... >> 'finds the first window where the class name start with ClassName ...
    (microsoft.public.excel.programming)