Swagbucks Auto Login Problems

Discussion in 'Programming' started by Ghst, Feb 7, 2010.

Thread Status:
Not open for further replies.
  1. Ghst

    Ghst Old School old school member

    Joined:
    Nov 14, 2009
    Likes Received:
    0
    Offline
    I'm using visual Basics 2008 Express, I have this code on the "Go" Button of My mainform. The program shows this error: "Object reference not set to an instance of an object." Here is the code I'm trying to get to work.The code stops on the line that is underlined. I really need help getting my app to Log in. (Hell I can't get it to fill the text boxes)


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    WebBrowser1.Navigate(ComboBox1.Text)

    WebBrowser1.Document.GetElementById("emailAddress").SetAttribute("type", login.Text)
    WebBrowser1.Document.GetElementById("pswd").SetAttribute("type", login.Text)
    WebBrowser1.Document.GetElementById("btn_login").InvokeMember("click")

    End Sub
  2. waldo

    waldo Old School old school member

    Joined:
    Jan 16, 2010
    Likes Received:
    0
    Offline
    This should work:

    PHP:
     Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandles Button1.Click
            WebBrowser1
    .Navigate(ComboBox1.Text)
        
    End Sub

        
    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As ObjectByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgsHandles WebBrowser1.DocumentCompleted
            WebBrowser1
    .Document.GetElementById("emailAddress").SetAttribute("type"login.Text)
            
    WebBrowser1.Document.GetElementById("pswd").SetAttribute("type"login.Text)
            
    WebBrowser1.Document.GetElementById("btn_login").InvokeMember("click")
        
    End Sub
    It will wait for the webbrowser to fully loaded before it send all those value.
  3. Ghst

    Ghst Old School old school member

    Joined:
    Nov 14, 2009
    Likes Received:
    0
    Offline
    Still Waiting

    Thanks for your Time Waldo. Ok I tried the code under webbrowser1.Documents Complete. and No Dice. It navigates to the page then It just sits there. Could it be that the constantly changing Notice in the center of the page is not allowing the page to become inactive? Anyway Thanks for the help I sure need it. Oh this time it didn't flag any lines of code.Also I am running in debug mode in cast that may have something to do with it.
  4. waldo

    waldo Old School old school member

    Joined:
    Jan 16, 2010
    Likes Received:
    0
    Offline
    Check this area of code:

    PHP:
    WebBrowser1.Document.GetElementById("emailAddress").SetAttribute("type"login.Text)
            
    WebBrowser1.Document.GetElementById("pswd").SetAttribute("type"login.Text)
            
    WebBrowser1.Document.GetElementById("btn_login").InvokeMember("click")
    Tell me if you still stuck (I can give the correct code now. But if you want to learn, do it yourself first).
  5. Ghst

    Ghst Old School old school member

    Joined:
    Nov 14, 2009
    Likes Received:
    0
    Offline
    Ok I give

    Waldo, I have tried all my reasonable options. I even tried this:



    HTML:
     Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
            WebBrowser1.Navigate(ComboBox1.Text)
    
            WebBrowser1.Document.GetElementById("emailAddress").SetAttribute("type", login.Text)
            WebBrowser1.Document.GetElementById("pswd").SetAttribute("type", login.Text)
            WebBrowser1.Document.GetElementById("btn_login").InvokeMember("click")
        End Sub  
    That causes quite a disturbance when it navigated to the website. Every thing started flickering and flashing But it still wouldn't fill those textboxes with the proper content.Also I found out that the Id=emailAddress should be Id=emailAddressLocal As seen In this source code of the login Box.

    HTML:
    <form name="frmLogIn-tbar" id="signInBoxLocal" method="post" action="/?cmd=sb-login&amp;from=/?cmd=home">
                            
                                <label class="loginLabel">Email Address or Swag Name:</label>
                                <input gtbfieldid="5" title="Enter your email address" name="emailAddress" id="emailAddressLocal" class="loginInput" onkeypress="return enterLoginTBLocal(event);" type="text">
                                <label class="loginLabel">Password</label>
                                <input title="Enter your password" name="pswd" id="pswdLocal" class="loginInput" onkeypress="return enterLoginTBLocal(event);" type="password">
                                <img src="/content/swagbucks-com/images/fbLogin_button.jpg" onclick="initFacebook(TBFCCallback);" class="btn-login" style="float: left; margin-right: 4px;" id="foo96"><img src="/content/swagbucks-com/images/login_button.jpg" onclick="logInTBLocal();" class="btn-login" style="float: left;"><div class="clear"></div>
    
                                <a href="#" onclick="sendEmailTBLocal(); return false" class="emailPass">Email Password</a>
                                <input name="persist" id="persistLocal" checked="checked" onkeypress="return enterLoginTBLocal(event);" class="persistBox" onchange="prettyCheckbox('persist',this)" type="checkbox">
                                <label for="persistLocal" class="persistLabel">Remember Me</label>
                                <div class="clear"></div>
    Ok please show me what I'm doing wrong. Thanks
  6. waldo

    waldo Old School old school member

    Joined:
    Jan 16, 2010
    Likes Received:
    0
    Offline
    1. As you already noticed, the ids are: emailAddressLocal and pswdLocal.
    2. So here are the code to fill the content of the textbox:
    PHP:
    WebBrowser1.Document.GetElementById("emailAddressLocal").SetAttribute("value"TextBox1.Text)
            
    WebBrowser1.Document.GetElementById("pswdLocal").SetAttribute("value"TextBox2.Text)
    Do notice that there are 2 textbox there.

    3. To send click is a little bit tricky as they use image as a button. But here you go:
    PHP:
    'collect all <img> tag name
            Dim elemCollec As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("img")
            '
    iterate each <imgfound to look for unique string of the button
            
    For Each tagname As HtmlElement In elemCollec
                Dim ctrlname 
    As String tagname.GetAttribute("src").ToString   'get atribute with src
                If ctrlname.Equals("http://www.swagbucks.com/content/swagbucks-com/images/login_button.jpg") Then '
    match with the buttin image
                    tagname
    .InvokeMember("click")   'invoke click
                End If
            Next

    The code above should work. Tell me if you need further help.
  7. Ghst

    Ghst Old School old school member

    Joined:
    Nov 14, 2009
    Likes Received:
    0
    Offline
    I still can't get this to work. The login info is not being sent to the pages login form.What to do?
  8. waldo

    waldo Old School old school member

    Joined:
    Jan 16, 2010
    Likes Received:
    0
    Offline
    Show me your code.
  9. Ghst

    Ghst Old School old school member

    Joined:
    Nov 14, 2009
    Likes Received:
    0
    Offline
    Here is all my code:

    HTML:
    Private Sub lblPass_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    
        End Sub
    
    
        Private Sub btnGet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGet.Click
    
            login.Show()
    
        End Sub
    
        Private Sub txtUser_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
    
    
        End Sub
    
        Private Sub SwaggerLee1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            
        End Sub
    
    
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            WebBrowser1.Navigate(ComboBox1.Text)
    
        End Sub
    
    
        Private Sub lblUser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblUser.Click
    
        End Sub
    
        Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
           WebBrowser1.Document.GetElementById("emailAddressLocal").SetAttribute("value", lblUser.Text)
            WebBrowser1.Document.GetElementById("pswdLocal").SetAttribute("value", lblPass.Text)
                    WebBrowser1.Document.GetElementById("btn_login").InvokeMember("click")
            'collect all <img> tag name
            Dim elemCollec As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("img")
            'iterate each <img> found to look for unique string of the button
            For Each tagname As HtmlElement In elemCollec
                Dim ctrlname As String = tagname.GetAttribute("src").ToString   'get atribute with src
                If ctrlname.Equals("http://www.swagbucks.com/content/swagbucks-com/images/login_button.jpg") Then 'match with the buttin image
                    tagname.InvokeMember("click")
                End If
            Next
        End Sub
    
    
        Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    
        End Sub
    
        Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
    
        End Sub
           
    End Class
    I also tried ti add webbrowser1.Navigate.(signInBoxLocal) Between the "document complete" and the "webbrowser Get elements" commands. This intered the signinBoxLocal text into Swaggs search and it did a search for "signinBoxLocal" but still no login. Notice that I don't have TextBox1 and TextBox2 in my code because They haven't been declared. My lblUser = My.Username in my login text file.
  10. waldo

    waldo Old School old school member

    Joined:
    Jan 16, 2010
    Likes Received:
    0
    Offline
    The only thing that I changed from your code was removing this line:

    PHP:
    WebBrowser1.Document.GetElementById("btn_login").InvokeMember("click")
    The url that I used:
    Code:
    http://www.swagbucks.com
    After I clicked button1, it navigate to the URL, and after finished loading, it send the username and password from the lblUser.Txt and lblPass.Txt. Then it click the login button.

    Here is the full code:
    PHP:
    Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandles Button1.Click
            WebBrowser1
    .Navigate(ComboBox1.Text)
        
    End Sub

        
    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.ObjectByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgsHandles WebBrowser1.DocumentCompleted
            WebBrowser1
    .Document.GetElementById("emailAddressLocal").SetAttribute("value"lblUser.Text)
            
    WebBrowser1.Document.GetElementById("pswdLocal").SetAttribute("value"lblPass.Text)
            
    'WebBrowser1.Document.GetElementById("btn_login").InvokeMember("click")
            '
    collect all <imgtag name
            Dim elemCollec 
    As HtmlElementCollection WebBrowser1.Document.GetElementsByTagName("img")
            
    'iterate each <img> found to look for unique string of the button
            For Each tagname As HtmlElement In elemCollec
                Dim ctrlname As String = tagname.GetAttribute("src").ToString   '
    get atribute with src
                
    If ctrlname.Equals("http://www.swagbucks.com/content/swagbucks-com/images/login_button.jpg"Then 'match with the buttin image
                    tagname.InvokeMember("click")
                End If
            Next
        End Sub
  11. Ghst

    Ghst Old School old school member

    Joined:
    Nov 14, 2009
    Likes Received:
    0
    Offline
    Well Now I have Half of it!

    Ok I had to do a lot of finagling To get the code to this point. Surprisingly it was Your (waldo) button click code that helped me get both username and password to load into the site's text boxes. But I lack the code to click the login Button. any way here is the code so far.


    HTML:
     Private username, password As String
    
        Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    
            Login(username, password)
    
        End Sub
    
    
    
    
    
        Private Sub Login(ByVal username As String, ByVal password As String)
    
            Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")
    
            For Each curElement As HtmlElement In theElementCollection
                Dim controlName As String = curElement.GetAttribute("id").ToString
                If controlName = "emailAddressLocal" Then
                    curElement.SetAttribute("Value", lblUser.Text)
                ElseIf controlName = "pswdLocal" Then
                    curElement.SetAttribute("Value", lblPass.Text)
                End If
            Next
        End Sub
    Is there any way to add another "If" for the invoke click?
  12. waldo

    waldo Old School old school member

    Joined:
    Jan 16, 2010
    Likes Received:
    0
    Offline
    Do you meant this?
    PHP:
     Dim elemCollec As HtmlElementCollection WebBrowser1.Document.GetElementsByTagName("img")
            
    'iterate each <img> found to look for unique string of the button
            For Each tagname As HtmlElement In elemCollec
                Dim ctrlname As String = tagname.GetAttribute("src").ToString   '
    get atribute with src
                
    If ctrlname.Equals("http://www.swagbucks.com/content/swagbucks-com/images/login_button.jpg")  'Then match with the button image
                    tagname.InvokeMember("click")
                End If
            Next
    That code search for <img> tag and the loop will look for the image source and when it found, it invokes the click.
  13. Ghst

    Ghst Old School old school member

    Joined:
    Nov 14, 2009
    Likes Received:
    0
    Offline
    I'm curious about this
    What is "scr" when I tried the code as you posted it kept opening up 3 more windows to login to twitter, facebook and Yahoo Search. Then It would ask me my login info and start hitting me with several error messages. but I could tell that the button click was happening only repeatedly.Causing the windows that I closed to reopean. Anyway I think that your button click code has to be modified to get it to work. I'm gettin excited cause I can now see my username and pass in the boxes I just gotta figure how to send that click to the Button. Thanks So much for your helping me with this!
  14. waldo

    waldo Old School old school member

    Joined:
    Jan 16, 2010
    Likes Received:
    0
    Offline
    That code is specifically for swagbucks login page since they use image as a button.

    If it use normal button like twitter, then you can use any method that can be found in this section.
  15. Ghst

    Ghst Old School old school member

    Joined:
    Nov 14, 2009
    Likes Received:
    0
    Offline
    Absolutely everything that I have tried has failed miserably in auto clicking the login button. Are there any suggestions?
  16. Ghst

    Ghst Old School old school member

    Joined:
    Nov 14, 2009
    Likes Received:
    0
    Offline
    Here is the code that I'm trying to get to click the login Button. I've tried everything, That I can think of. I sure can use some help! There is a btn1 btnLogin that I've also tried from the source code but still no dice. Please HELP!



    HTML:
            For Each curElement As HtmlElement In theWElementCollection
                Dim controlName As String = curElement.GetAttribute(" tagname").ToString
                If controlName = "frmLogIn-tbar" Then
                    WebBrowser1.Document.GetElementById("btn1 btnlogin").InvokeMember("click")
                End If
            Next
    
            System.Threading.Thread.Sleep(1000)
    
  17. alkmie

    alkmie Old School old school member

    Joined:
    Feb 25, 2010
    Likes Received:
    0
    Offline
  18. Ghst

    Ghst Old School old school member

    Joined:
    Nov 14, 2009
    Likes Received:
    0
    Offline
    I got it!

    I finally have a auto logger! The solution was a simple one line of code added to the bottom of:


    F
    HTML:
    or Each curElement As HtmlElement In theElementCollection
                Dim controlName As String = curElement.GetAttribute("id").ToString
                If controlName = "emailAddressLocal" Then
                    curElement.SetAttribute("Value", lblUser.Text)
                ElseIf controlName = "pswdLocal" Then
                    curElement.SetAttribute("Value", lblPass.Text)
                End If
            Next
    No src image callin or href It is so simple even Ghst can do it!
  19. alkmie

    alkmie Old School old school member

    Joined:
    Feb 25, 2010
    Likes Received:
    0
    Offline
    CONGRAT!!!!! I know how frustrating the whole trial and error programming can be. And thanks for sharing the code also.

    Just out of curiosity how are you going to get around the captchas? Sence they have updated ive only seen it happen one time so maybe it wont be a big deal.

    I was thinking bout looking for the swagbuck pic after ever search and if it finds it stop searching and ding the user.

    *Edit Can you plz post the full code?

    This is what I have its add the user names but no click
    Code:
    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
    
            Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")
    
            WebBrowser1.Document.GetElementById("emailAddressLocal").SetAttribute("value", My.Settings.User)
            WebBrowser1.Document.GetElementById("pswdLocal").SetAttribute("value", My.Settings.Pass)
            'WebBrowser1.Document.GetElementById("btn_login").InvokeMember("click")
            'collect all <img> tag name
            Dim elemCollec As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("img")
            'iterate each <img> found to look for unique string of the button
            For Each curElement As HtmlElement In theElementCollection
                Dim controlName As String = curElement.GetAttribute(" tagname").ToString
                If controlName = "frmLogIn-tbar" Then
                    WebBrowser1.Document.GetElementById("btn1 btnlogin").InvokeMember("click")
                End If
            Next
    
        End Sub
    
    
    
  20. Ghst

    Ghst Old School old school member

    Joined:
    Nov 14, 2009
    Likes Received:
    0
    Offline
    Here is the code that I worked my arse off to get! look at the invokemember click statement. It took several weeks to get this one line right.


    HTML:
     Dim theWElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")
            For Each curElement As HtmlElement In theWElementCollection
                Dim controlName As String = curElement.GetAttribute("id").ToString
                If controlName = "emailAddressLocal" Then
                    curElement.SetAttribute("Value", lblUser.Text)
                ElseIf controlName = "pswdLocal" Then
                    curElement.SetAttribute("Value", lblPass.Text)
                    System.Threading.Thread.Sleep(3000)
                    WebBrowser1.Document.InvokeScript("logInTBLocal")
                End If
    Hope this Helps:bigsmile: Giv Rep if this logs you on!
Thread Status:
Not open for further replies.