Results 1 to 12 of 12

Thread: [RESOLVED] How to test if URL is completely loaded in WebBrowser

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2008
    Posts
    89

    Resolved [RESOLVED] How to test if URL is completely loaded in WebBrowser

    I need to make a condition such that my program waits until the webpage is completely loaded before executing my provided commands.

    If anyone could help that would be great.

    Thank you for reading

  2. #2
    Fanatic Member
    Join Date
    Nov 2007
    Posts
    520

    Re: How to test if URL is completely loaded in WebBrowser

    Code:
    if webbrowser1.isbusy = true then
    'do nothing
    else
    'do what you want
    end if

  3. #3
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,828

    Re: How to test if URL is completely loaded in WebBrowser

    You can also use the default, DocumentCompleted event for the WebBrowser control. Just create the event by double clicking on the component and then execute all of your code in it.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  4. #4
    Fanatic Member
    Join Date
    Nov 2007
    Posts
    520

    Re: How to test if URL is completely loaded in WebBrowser

    ah yes, forgot about that one.

    You could use either or.

  5. #5
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,828

    Re: How to test if URL is completely loaded in WebBrowser

    Quote Originally Posted by TCarter View Post
    Code:
    if webbrowser1.isbusy = true then
    'do nothing
    else
    'do what you want
    end if
    Also, I haven't tested it, but I don't think that will work. You'd probably need a loop instead of a conditional statement. With this code, it checks if the WebBrowser is busy, once, and then moves on. If it is busy, then it will move on and not give the WebBrowser time to complete.

    Although not usually suggested, the OP can also use a While statment to check if it's busu and use Application.DoEvents while it's busy.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Nov 2008
    Posts
    89

    Re: How to test if URL is completely loaded in WebBrowser

    Yes, I thought the same thing, the If statement will only check to see if it is loaded once. I need it to tell me when it is done loading.

    I'm not sure how to write the while loop to continuously check until it is loaded.

  7. #7
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: How to test if URL is completely loaded in WebBrowser

    If you want to do something as soon as page load is complete, use the DocumentCompleted event. In case you want to know at some random point whether the current page in webbrowser is fully loaded or not then use the ReadyState property.
    vb.net Code:
    1. If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
    2.     'whatever
    3. End If
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Nov 2008
    Posts
    89

    Re: How to test if URL is completely loaded in WebBrowser

    I'm still unsure of how to use DocumentCompleted.

    Let's say I navigate to "google.com"

    I want to wait until Google has been finished loading until I perform anything else.

  9. #9
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: How to test if URL is completely loaded in WebBrowser

    e.g.
    vb.net Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.     WebBrowser1.Navigate("http://www.google.com")
    3. End Sub
    4.  
    5. Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    6.     MessageBox.Show("Document loading completed!")
    7. End Sub
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  10. #10
    Fanatic Member
    Join Date
    Nov 2007
    Posts
    520

    Re: [RESOLVED] How to test if URL is completely loaded in WebBrowser

    a loop wouldnt be too far off depending on what he is doing...and if he didnt want to limit a webbrowser control to any 1 thing.

    Regardless, it is resolved.

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Nov 2008
    Posts
    89

    Re: [RESOLVED] How to test if URL is completely loaded in WebBrowser

    It's solved, and the DocumentCompleted option works perfect and is very efficient.

  12. #12
    New Member
    Join Date
    Aug 2015
    Posts
    1

    Re: How to test if URL is completely loaded in WebBrowser

    Hold on...

    As per the following answer:
    http://stackoverflow.com/a/32298026/2396732

    Since IE11 informs of DocumentCompleted multiple times, so it's better to check what URL is completed:

    Code:
    ' Page, sub-frame or resource was totally loaded.
    Private Sub webBrowser1_DocumentCompleted(sender As Object, _ 
        e As WebBrowserDocumentCompletedEventArgs) _ 
        Handles webBrowser1.DocumentCompleted
    
        ' Check if finally the full page was loaded (inc. sub-frames, javascripts, etc)
        If e.Url.ToString = webBrowser1.Url.ToString Then
            ' Only now you are sure!
            fullyLoaded = True
        End If
    
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width