1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Gather login page loading faster than text filling the forms

Discussion in 'Visual Basic .NET' started by simpleonlinetest, Mar 10, 2011.

  1. simpleonlinetest

    simpleonlinetest Regular Member

    Joined:
    Feb 18, 2010
    Messages:
    208
    Likes Received:
    25
    I am trying to code up a Gather login and post submitter.

    The app will log in if I don't have another page to navigate too but if I have navigate to another page the app always skips to the next page before the first page can log me in.

    Is there a way to pause the app or have it wait before it navigates to the next page?

    I have the entire code under the Webbrowser1_document completed page but it still goes crazy. Any ideas?

    Thanks

    Code:
        Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
            If statustext = 1 Then
    
                WebBrowser1.Document.GetElementById("username").SetAttribute("value", TextBox1.Text)
                WebBrowser1.Document.GetElementById("password").SetAttribute("value", TextBox2.Text)
    
                For Each element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("input")
    
                    If element.GetAttribute("value") = "Sign In" Then
    
                        element.InvokeMember("click")
                    End If
                Next
            
    
                WebBrowser1.Navigate("http://www.gather.com/sharePosts.action")
    
            End If
            statustext = 0
    
        End Sub
     
  2. shudogg

    shudogg Regular Member

    Joined:
    Sep 23, 2008
    Messages:
    412
    Likes Received:
    153
    Occupation:
    Internet Marketing
    Location:
    Indiana
    Home Page:
    ummm.. why the hell do you have all your code in the document complete section??? Aside the fact your using a web browser app to begin with (gross). You should just use a webrequest..

    Above your code, set a public boolean:
    Code:
    Dim bWBComplete as boolean
    In your document complete, set the boolean to = True. So every time the WB is done loading, it will set the flag.

    Im not sure why you have statustext = 1 ?? Also your code says to click the "Sign In" button... but doesn't have code to full the username/password boxes and actually sign it.. it just clicks the signin button, then navigates to another page?? Not sure what your doing there..

    Put the code you have shown us, in it's own function or sub:
    Code:
    Private Sub LoginGather(ByVal username as string, ByVal password as string)
    
    WebBrowser1.Document.GetElementById("password").SetAttribute("value", TextBox2.Text)
    
                For Each element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("input")
    
                    If element.GetAttribute("value") = "Sign In" Then
    
                        element.InvokeMember("click")
                    End If
                Next
    
      'Not sure what your doing here. You should have code to fill the login info and login        
    
                WebBrowser1.Navigate("http://www.gather.com/sharePosts.action")
                'why are you navigating here.. you didnt even login!!! ??
            End If
    End Sub
    
    Say you want the LoginGather(xx) sub to execute after navigating to the homepage, and waiting until the page fully loaded.. I will use another Sub for example/ease.. you could use a Button or whatever you need.. this is just an example:

    Code:
    Private Sub DoIt()
    
    Dim username as string = "bob", password as string = "bobspass"
    Dim url as string = "http://www.gather.com"
    WebBrowser1.Navigate(url)
    
    'loop/wait until page is fully loaded!
    Do Until (bWBComplete)
       Application.DoEvents()
    Loop
    
    'if we are here, the browser is loaded!
    LoginGather(username,password)
    End Sub
    
    Thats just a flyby example of the handling. You will need to tweak it, check it for errors. Its 3AM, so it may have an error or two.. I don't recommend using the Thread.Sleep() in the loop while we are waiting for the browser to complete as it will hang the GUI. The application doevents allows the gui to still be responsive while we are looping. Since we really aren't doing anything but waiting for the boolean flag to = true, there shouldnt be many resources being eaten.
     
  3. Hydrogen

    Hydrogen Newbie

    Joined:
    Dec 30, 2009
    Messages:
    39
    Likes Received:
    23
    Occupation:
    Co-Owner of AdvertMarketing
    Home Page:
    Screw Browser control, use httpWebRequest it's much more accurate, as you really do not have any real control over when the Browser control finishes or not. Plus on top of that httpWebRequest is much more faster, able to be multi-threaded, and allows you to do a whole host of other things like Set Custom Referrers, User-Agents, Submit Form Data using POST or switch it over to receive html with the GET command.

    I suggest stop whatever you are working on right now, delete the browser control from your app (And your brain) and start reading up on how to use httpWebRequest.