Link to home
Start Free TrialLog in
Avatar of drus9
drus9

asked on

Verify that the webbrowser has fully loaded a web page

Hey all,
i have script that opens the browser,navigates to a webpage & insures that the webpage has fully loaded by using

Do while mIE.readystate < 4
   DoEvents
Loop

before running anything else.    this works fine

My problem is after running this i want to be able to navigate to a diffrent webpage without closing the browser and insure that this new webpage has fully loaded before running anything else.

Any Help would realy be appreciated
Reg,
drus9
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

You can use the DownloadComplete event of the WebBrowser control.
Avatar of drus9
drus9

ASKER

Tried it not giving reliable results
Declare a form level variable (mintPage) to track which page you are processing, then:

Option Explicit
Private mintPage As Integer

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    Select Case mintPage
    Case 1
    'Code to run after 1st page loaded
    Case 2
    'Code to run after 2nd page loaded
       
    End If
End Sub

This is very reliable.  I use this code all the time to auto-navigate series of links.  You need to keep track of which page you are processing through the mintPage variable.
Show us your code.
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
if (pDisp is webbrowser1) then

     ' do what you want
     msgbox "Full loaded"
end if

End Sub

Another way (I don't believe in it , eally)


do until webbrowser1.busy<>true
doevents
loop
' continue with your code here........



Avatar of drus9

ASKER

just sample code  of what i'm doing but getting unreliable results.

Private Sub web_DocumentComplete(ByVal pDisp As Object, URL As Variant)
       
    Select Case webPage
     Case 1
        web.Navigate "www.something.com"
     
     Case 2
        web.Document.All("username").Value = " dgshshsh"
        web.Document.All("password").Value = "dgdhdhshs"
        web.Document.Forms(submit_form).submit
        btnClick "OK"
       
     Case 3
        web.Navigate "www.somethingelse.com"
       
     Case 4
        web.Document.All("username").Value = "dghdhdhdc"
        web.Document.All("password").Value = "dhdjdjd"
        web.Document.Forms(submit_form).submit
         
   End Select

 webPage = webPage + 1

End Sub
ASKER CERTIFIED SOLUTION
Avatar of Richie_Simonetti
Richie_Simonetti
Flag of Argentina image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excellent point Richie.  The event will fire for each frame that is fully loaded and only when the entire page is loaded will the (pDisp is webbrowser1) be true.
You are right, Paul!
:)
Avatar of drus9

ASKER

Cheers Richie
Cheers to you too and thanks for the points!