Page 1 of 1

wait for website to load before running a script

Posted: 07 Aug 2017 14:12
by jap
Hi,

I need help on this. Im running on Windows 10 / IE 11.
Here's a part of the script inside my batchfile.
I would like for the website to load first before running any other script, BUT in this case website is not loading but it already jumps to the "Page load successfully!"

Code: Select all

IELink= "http://www.google.com"
Set IE = CreateObject("InternetExplorer.Application")
Set X = CreateObject("Wscript.Shell")
IE.AddressBar = false
IE.MenuBar = false
IE.StatusBar = true
IE.ToolBar = false
IE.Visible = false
IE.Top = 0
IE.Left = 0
IE.FullScreen = true
W = IE.Width
H = IE.Height
IE.FullScreen = false
IE.Width = W
IE.Height = H
IE.Visible = true
IE.Navigate IELink
Function Wait(IE)
  Do
    WScript.Sleep 200
  Loop While IE.ReadyState < 4 And IE.Busy
End Function
WScript.Echo "Page load successfully!"
WScript.quit

Re: wait for website to load before running a script

Posted: 07 Aug 2017 14:26
by aGerman
No idea what you're doing there. It's VBScript and actually can't be part of a batch script. Anyway, you defined a Wait function but you don't call it. It however doesn't make much sense to use a function in your case. Just remove the lines
Function Wait(IE)
and
End Function
and only keep the loop in between.

Steffen

Re: wait for website to load before running a script

Posted: 07 Aug 2017 18:31
by Hackoo
First, this not a batch script , it's a vbscript
You can take a look at this https://stackoverflow.com/questions/232 ... ve#tab-top

And here is an example inspired from it :
Just copy and paste in your notepad with this name and execute it:
IE_Load.vbs

Code: Select all

Option Explicit
Dim IE,IELink
Set IE = CreateObject("InternetExplorer.Application")
IELink= "https://www.google.com"
IE.AddressBar = false
IE.MenuBar = false
IE.StatusBar = true
IE.ToolBar = false
IE.FullScreen = true
IE.Visible = true
IE.Navigate IELink
On Error Resume Next
Do
    If IE.ReadyState = 4 And IE.Busy Then
        If Err = 0 Then
            Exit Do
        Else
            Err.Clear
        End If
    End If
    WScript.Sleep 10
Loop
On Error Goto 0
WScript.Echo "Page load successfully!"
WScript.quit