Results 1 to 5 of 5

Thread: [RESOLVED] WebBrowser1.Navigate wait for finish

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2010
    Posts
    36

    Resolved [RESOLVED] WebBrowser1.Navigate wait for finish

    Ok i want the browser to so something like this:

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    2.         WebBrowser1.Document.GetElementById("Login").SetAttribute("Value",TextBox1.Text)
    3.         WebBrowser1.Document.GetElementById("pass").SetAttribute("Value",TextBox2.Text)
    4.  
    5.         WebBrowser1.Document.GetElementById("login).InvokeMember("click")
    6.  
    7.        'now the problem is that the following statments finishes up before the preceding statment
    8.  
    9.         Dim PageTeamElements As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("a")
    10.         For Each CurElement As HtmlElement In PageTeamElements
    11.             CurElement.GetAttribute("href")
    12.             TextBox3.Text = TextBox3.Text & CurElement.GetAttribute("href") & Environment.NewLine
    13.         Next
    14.  
    15.         Dim PageUserElements As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("img")
    16.         For Each CurElement As HtmlElement In PageUserElements
    17.             CurElement.GetAttribute("src")
    18.             TextBox3.Text = TextBox3.Text & CurElement.GetAttribute("src") & Environment.NewLine
    19.         Next
    20.  
    21.       End Sub
    How can i wait for browser to do
    WebBrowser1.Document.GetElementById("login).InvokeMember("click")
    then fetch data
    and then again to navigate somewhere else (by using WebBrowser1.Navigate("some other link"))
    and to fetch data from there completes

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: WebBrowser1.Navigate wait for finish

    You handle the webbrowser.documentcompleted event and examine the Url property of the webbrowserdocumentcompletedeventargs e to find out which page has just completed and proceed accordingly.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2010
    Posts
    36

    Re: WebBrowser1.Navigate wait for finish

    i have been trying to figure it out for hours but i just can't get it.

    The problem is that i have a WebBrowser1.Navigate on the form load, so document complete happens a few times

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: WebBrowser1.Navigate wait for finish

    The IsBusy and State properties of the WebBrowser can tell you whether a sub-document is still loading.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2010
    Posts
    36

    Re: WebBrowser1.Navigate wait for finish

    vb Code:
    1. If Not WebBrowser1.IsBusy Then
    2.             If WebBrowser1.Url.AbsoluteUri = "url i need" Then
    3. do something
    4. end if
    5. end if

    got it done with this

Tags for this Thread

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