Auto login to a webbrowser - vb.net

Hi I am working on a forum project, currently I have a win form that allows the user to login to the forum - this part works fine.
After the user logs in I want a new form to open that will display the forum, how can I use the login details the user entered - pass them to the login form for the website to the user is automatically logged in so to speak
This is the code I am using for user login
If forumLogin.Verify(RadTextBoxUser.Text, RadTextBoxPass.Text) Then
I am using SMF forums not usre how I can pass RadTextBoxUser.Text and RadTextBoxPass.Text to the new form.
I cam accros this code which looked promising
Public Class Browser
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Part 1: Load Yahoo login page in Form_Load event
WebBrowser1.Navigate("http://websiteurl/")
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
'Part 2: Locate the Username TextBox and automatically input your username
'<INPUT class=yreg_ipt id=username maxLength=96 size=17 name=login>
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 = "username" Then
curElement.SetAttribute("Value", LoginForm.RadTextBoxUser.Text)
End If
Next
'Part 3: Locate the Password TextBox and automatically input your password
'<INPUT class=yreg_ipt id=passwd type=password maxLength=64 size=17 value="" name=passwd>
theElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")
For Each curElement As HtmlElement In theElementCollection
Dim controlName As String = curElement.GetAttribute("id").ToString
If controlName = "passwd" Then
curElement.SetAttribute("Value", LoginForm.RadTextBoxPass.Text)
End If
Next
'Part 4: Locate the "Sign In" Button and automatically click it
'<INPUT type=submit value="Sign In" name=.save>
theElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")
For Each curElement As HtmlElement In theElementCollection
If curElement.GetAttribute("value").Equals("Sign In") Then
curElement.InvokeMember("click")
'Javascript has a click method for we need to invoke on the current submit button element.
End If
Next
End Sub
End Class
Code taken from http://social.msdn.microsoft.com/Forums/vstudio/en-US/0b77ca8c-48ce-4fa8-9367-c7491aa359b0/yahoo-login-via-systemnetsockets-namespace?forum=vbgeneral
I get an error when the browser loads object doesn't support this property method?
http://prntscr.com/3xygks
Any suggestions?
Ok so I got it working
On a slightly different note you used to be able to re-arrange where the forms would appear when your program runs I don't see that option in VS2012?

Related

Sub To Summarize Click Events

I have a windows form app where a user clicks a menu item to open a form. Once the menu item is clicked, it checks whether form is open and notifies user if form is open else it opens the form. The code for this is as below
Private Sub UsersBarButtonItem_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles UsersBarButtonItem.ItemClick
If Application.OpenForms().OfType(Of Users).Any Then
MessageBox.Show("Form Is Open", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
For Each openform In Application.OpenForms()
If TypeOf (openform) Is Users Then CType(openform, Users).BringToFront()
Next
Else
Dim Form As New Users
Form.MdiParent = Me
Form.Show()
End If
End Sub
I would like a subroutine to help me avoid repetiting this code for each menu item click events.
Ok, with a bit of help from This thread, you could use reflection/linq to create a new instance of the passed form from its' .Name string If you find a better way, I would be interested to learn myself.
Private Sub ButtonFormB_Click(sender As Object, e As EventArgs) Handles ButtonFormB.Click
CheckForm(FormB)
End Sub
Private Sub CheckForm(Frm As Form)
For Each OpnForm As Form In Application.OpenForms
If OpnForm Is Frm Then
OpnForm.BringToFront()
Exit Sub
End If
Next
Dim formType =
Reflection.Assembly.GetExecutingAssembly().GetTypes().Where(Function(a) a.BaseType = GetType(Form) AndAlso a.Name = Frm.Name).FirstOrDefault()
If formType IsNot Nothing Then
Dim NewForm As Form = CType(Activator.CreateInstance(formType), Form)
NewForm.Show()
End If
End Sub

COINS.PH login panel from vb.net winform

I want to create a login form for coins.ph but the result isn't what I expected, once I clicked the Sign In button from the form, everything in the username and password textbox will be written in the webbrowser but it wont click the sign in button from the webbrowser. But when I tried clicking the sign in button from the webbrowser, it says that no data were written.
Heres my code:
Private Sub BunifuThinButton21_Click(sender As Object, e As EventArgs) Handles BunifuThinButton21.Click
For Each username As HtmlElement In WebBrowser1.Document.GetElementsByTagName("input")
If username.OuterHtml.Contains("name=""username""") Then
username.SetAttribute("value", BunifuMetroTextbox1.Text)
Exit For
End If
Next
For Each password As HtmlElement In WebBrowser1.Document.GetElementsByTagName("input")
If password.OuterHtml.Contains("name=""password""") Then
password.SetAttribute("value", BunifuMetroTextbox2.Text)
Exit For
End If
Next
For Each signIN As HtmlElement In WebBrowser1.Document.GetElementsByTagName("button")
If signIN.GetAttribute("class") = "login-button login-form__button" Then
signIN.InvokeMember("click")
Timer1.Enabled = False
Exit For
End If
Next
End Sub
Or what other approach should I use which is easier for me, they said that web page changes elements sometime. If api, theres no api for login pages.

Visual Basic: Clicking a button on a webpage

I am trying to make a program click the login button of twitch.tv. I have tried many methods but the thing is that I can not find the button ID of that button. I assume that it doesn't have one and I need help clicking it. What commands would I used to click that button if it has no ID? Here is the HTML of that button
<div class="buttons"> <button class="primary_button" tabindex="10" type="submit"><span class="">Log In</span>
So as you see I have no ID on that button that says Log In.
Basically what I'm asking is, what is the coding command for clicking buttons without a ID. Buttons like this one with no ID, just a class and a type.
The following is my code so far for typing in my log in info but not hitting the submit button
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim allelements As HtmlElementCollection = WebBrowser1.Document.All
WebBrowser1.Document.GetElementById("login_user_login").SetAttribute("Value", "123#gmail.com")
WebBrowser1.Document.GetElementById("user[password]").SetAttribute("Value", "123#gmail.com")
'Type = "submit"
If webpageelement.getattribute("type") = "Log In" Then
webpageelement.invokemember("click")
End If
End Sub
ieDoc = MyBrowser.Document
With ieDoc.forms(0)
.UserName.Value = loguser
.Password.Value = logpasswrd
.submit
End With

Using Windows Forms to open a browser and call a Javascript function

I'm new to this so please bear with me. I am using a VB.NET (2.0) Windows Forms application.
On Form_Load(), I open up IE browser, which then navigates to a particular URL with a login form. It passes the u/n and p/w values to this form and gets the button id and calls the click function on it, causing the browser to redirect to the web site as a user. It then executes a script on that page, which displays a bulk upload control.
I want to be able to get/set the value in the text box on this page.
'-->>> theTextBox = Nothing. After executing the script, the bulk update div is 'created in the page by the script. If we do a View Source, we can see an element with ID as 'TXT_UPLOAD as below.
'INPUT type="TEXT" id="TXT_UPLOAD" size="78" onblur="checkFileType(this,this.value, 'true)"
Here is my code:
Dim IE As New Object
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim URL As String = "http://someurl.com/"
Try
IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate("https://someurl.com/Login.aspx?")
Threading.Thread.Sleep(3000)
WaitUntil(IE.Document)
IE.Document.getElementById("tb_login").value = "username"
IE.Document.getElementById("tb_password").value = "password"
Dim theButton
theButton = IE.Document.getElementById("btn_login")
theButton.Click()
Threading.Thread.Sleep(5000)
WaitUntil(IE.Document)
IE.Document.parentWindow.execScript("parent.showApplication('Bulk Update', 712030600,-1,712000000,1);")
Dim theTextBox
theTextBox = IE.Document.getElementById("TXT_UPLOAD")
theTextBox.Focus()
Debug.Print(theTextBox.value)
theTextBox.Value = "C:\NV\CV\CLWR_NA_CHG_UPLOAD_2014313.csv"
IE.Document.parentWindow.execScript("parent.logOff();")
Catch ex As Exception
MsgBox(ex.ToString)
Threading.Thread.Sleep(5000)
WaitUntil(IE.Document)
IE.Document.parentWindow.execScript("parent.logOff();")
End Try
IE = Nothing
'IE.kill()
'IE.Quit()
End
End Sub

VB: Make webbrowser1 click a button on a webpage

Well, I guess title says most of it. I already know how to click a button within a browser but the code doesn't work on this pacific button. I hope this code is allowed on here, sorry if it's not...
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Button3.Enabled = True
Dim allelements As HtmlElementCollection = WebBrowser1.Document.All
For Each webpageelement As HtmlElement In allelements
'AMF Email
WebBrowser1.Document.GetElementById("Email").InnerText textbox1.text
'AMF Password
WebBrowser1.Document.GetElementById("password").InnerText = textbox2.text
'AMF Login Button
If webpageelement.GetAttribute("value") = "Login" Then
webpageelement.InvokeMember("click")
End If
Next
'Navigates to FB likes to begin the process
WebBrowser1.Navigate("http://addmefast.com/free_points/facebook_likes")
Button2.PerformClick()
End Sub
Okay so all this code works perfectly, but now I want it to click the "Like" button on this link: http://addmefast.com/free_points/facebook_likes
However, I can not find the correct value. Can anyone help get the correct value for the "Like" button on that page?
VB2012
When I try to "Inspect Element" on the button, this is all it shows;
<div class="btn3">
Like
</div>
You can use the following code to do this:
For Each elem as HtmlElement in WebBrowser1.Document.All
If elem.GetAttribute("class") = "btn3" Then
elem.InvokeMember("click")
End If
Next
Sorry if there is any mistakes here. I am use to using an IDE for my code...
I hope this helps,
Rodit