I'm trying to create a program to automatically log me in to Myspace. Yes, I am too lazy to login myself!
And sorry, but I'm not exactly using a WebBrowser, but something that's name is "SHDocVw" that I got by adding a reference to something for my project... And I have also added a reference to "Microsoft HTML Object Library".
I wrote the following code to edit the text in the "username" box on the Myspace home page.
Then I wrote the following code, this time using a new project with a WebBrowser, to provide the names of the elements I would need to use from the Myspace home page.
It provided the names of the username and password box that I would need to fill out.
So I modified the first code to fill the Username box with my email, but when I tested it out, the project became unresponsive for a couple seconds and then came with an error that "vshost.exe has encountered an error and needs to close....blah blah blah".
Can anyone help me out with this problem? I have been stumped on it for many days!!! If you can also help me figure out how to click the "Login" button on the homepage that would be helpful too! I'm using Visual Basic 2005 & Visual Basic 2008.
Personally, I believe that the problem is that the login form on the Myspace homepage may not be composed of a typical textbox or button. I think this because I tried my code out on the Google Homepage (to enter text and click "Search" button) and it worked like a charm. Or perhaps I need to provide an index in the code? Any help?
Oh, and I am using a computer running Windows XP.
Here is some more source code from my project to help explain some of the above:
And sorry, but I'm not exactly using a WebBrowser, but something that's name is "SHDocVw" that I got by adding a reference to something for my project... And I have also added a reference to "Microsoft HTML Object Library".
I wrote the following code to edit the text in the "username" box on the Myspace home page.
Code:
Private Sub SetTextboxText(ByVal Text As String)
DirectCast(GetCurrentWebForm.item("namehere"), mshtml.HTMLInputElement).value = "myemail"
End Sub
Code:
Dim hdoc As HtmlDocument = Me.WebBrowser1.Document
Dim elemcoll As HtmlElementCollection = hdoc.GetElementsByTagName("input")
For Each helement As HtmlElement In elemcoll
If Not helement.GetAttribute("Type") = "hidden" Then
Me.TextBox1.Text = TextBox1.Text & Environment.NewLine & helement.Name
End If
Next
So I modified the first code to fill the Username box with my email, but when I tested it out, the project became unresponsive for a couple seconds and then came with an error that "vshost.exe has encountered an error and needs to close....blah blah blah".
Can anyone help me out with this problem? I have been stumped on it for many days!!! If you can also help me figure out how to click the "Login" button on the homepage that would be helpful too! I'm using Visual Basic 2005 & Visual Basic 2008.
Personally, I believe that the problem is that the login form on the Myspace homepage may not be composed of a typical textbox or button. I think this because I tried my code out on the Google Homepage (to enter text and click "Search" button) and it worked like a charm. Or perhaps I need to provide an index in the code? Any help?
Oh, and I am using a computer running Windows XP.
Here is some more source code from my project to help explain some of the above:
Code:
Private Function GetCurrentWebDoc() As mshtml.HTMLDocument
Try
Return DirectCast(wb.Document, mshtml.HTMLDocument)
Catch ex As Exception
Return Nothing
End Try
End Function
Code:
Private Function GetCurrentWebForm() As mshtml.HTMLFormElement
Try
If GetCurrentWebDoc.forms.length > 0 Then
Return DirectCast(GetCurrentWebDoc.forms.item(0), mshtml.HTMLFormElement)
Else
Return Nothing
End If
Catch ex As Exception
Return Nothing
End Try
End Function