Trying to autologin to a web site using a vb.net form application. I do not receive any exceptions or errors. I Navigate to my page, set the email and password attributes and then click the 'cmd' button on the webpage. Using Debug statements I have verified the attributes are set.
After I click the 'cmd' button on the webpage I get back the same page I started with and cannot find anything that tells me there was an exception or error.
I am able to login to the webpage using chrome or IE using the same email/password combination.
Here is my code.
Private mPageReady As Boolean = False
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
AddHandler Me.WebBrowser1.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter)
End Sub
Public Function LoginUser(pEmailAddress As String, pPassword As String) As Boolean
Dim IsOkay As Boolean = False
Dim myURL As String = "https://login.wlpc.com/index.php/"
Me.WebBrowser1.Navigate(myURL)
WaitForPageLoad()
Debug.WriteLine("After Navigate: " & Me.WebBrowser1.DocumentText)
Try
Me.WebBrowser1.Document.GetElementById("email").SetAttribute("value", pEmailAddress)
Debug.WriteLine("After assignment of email: " & Me.WebBrowser1.Document.GetElementById("email").GetAttribute("value"))
Me.WebBrowser1.Document.GetElementById("password").SetAttribute("value", pPassword)
Debug.WriteLine("After assignment of password: " & Me.WebBrowser1.Document.GetElementById("password").GetAttribute("value"))
Dim myDoc As HtmlDocument = Me.WebBrowser1.Document
Dim myCmd As HtmlElement = myDoc.All("cmd")
myCmd.InvokeMember("click")
WaitForPageLoad()
Debug.WriteLine("After click: " & Me.WebBrowser1.DocumentText)
IsOkay = True
Catch ex As Exception
IsOkay = False
End Try
Return IsOkay
End Function
Public Function GetPage(URL As String) As String
Debug.WriteLine(String.Format("Accessing {0}", URL))
Me.WebBrowser1.Navigate(URL)
WaitForPageLoad()
Dim pagedata As String = Me.WebBrowser1.DocumentText
Return pagedata
End Function
Public Sub WaitForPageLoad()
While Not mPageReady
Application.DoEvents()
End While
mPageReady = False
End Sub
Private Sub PageWaiter(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
If Me.WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
mPageReady = True
End If
End Sub
Private Sub BtnSignin_Click(sender As Object, e As EventArgs) Handles BtnSignin.Click
LoginUser(mEmailAddress, mPassword)
End Sub