0

I want to create an automatic login program for this website using VB.net and Internet Explorer as browser. I am able to write the username and the password in the right boxes but I am not able to click the "Login" button. Here is my code:

Public Class Form1

Dim appIE As Object ' InternetExplorer.Application
Dim UserN As Object ' MSHTML.IHTMLElement
Dim PW As Object ' MSHTML.IHTMLElement
Dim Element As Object ' HTMLButtonElement


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    appIE = CreateObject("InternetExplorer.Application")

    With appIE
        .Navigate("www.bwin.it")
        .Visible = True
    End With

    Do While appIE.Busy
    Loop

    UserN = appIE.Document.getElementsByName("ctl03$ctl12$loginview$baw_template$logincontrol$edtUsername")
    If Not UserN Is Nothing Then
        UserN(0).Value = "11111"
    End If

    PW = appIE.Document.getElementsByName("ctl03$ctl12$loginview$baw_template$logincontrol$edtPasswordDummy")
    If Not PW Is Nothing Then
        PW(0).Value = "aaaaaaaa"
    End If



End Sub
End Class

I tried different ways but I didn't get it yet. What am I missing?

Trisped
  • 5,705
  • 2
  • 45
  • 58
  • Does it have to be done entirely in vb.net, or can it be done using javascript? Seems javascript might be the easier way? – yougotiger Jun 02 '14 at 21:17
  • Hi yougotiger. I am using Visual Basic 2010 Express and I am really a noob about programming. Can I implement a javascript using the aforementioned program? – user3700761 Jun 02 '14 at 21:19
  • It would help if you told us what you have tried. Have you seen, e.g., [Perform a click on a Webbrowser control](http://stackoverflow.com/questions/5493276/perform-a-click-on-a-webbrowser-control)? – Andrew Morton Jun 02 '14 at 21:37
  • I have to agree with @Andrew, it would be really helpful if you gave more information like what you tried. – yougotiger Jun 03 '14 at 22:26

1 Answers1

0

Here's how you can do it all with vb.net code (assuming you're doing asp.net):

Dim isValid As Boolean = Membership.ValidateUser("username", "password")
If isValid Then
    FormsAuthentication.SetAuthCookie("username", False)
    'the redirect to the page.
End If

Note, that it won't show on the page that you are logged in unless you refresh so I suggest redirecting to a different page and start your interaction there.

yougotiger
  • 434
  • 4
  • 18