I am loading a website into a WebBrowser in a winform. I wish to login using a log and pass automatically via vb.net
I have the following code executing onc
I applied this logic:
DocumentCompleted event to run the code after the document completed.DocumentCompleted also raises when an iframe document completed, so to get rid of iframes use a criteria like comparing e.Url with the base url know.And it worked properly. It redirected to the same url and showed a red not authenticated message.
Code:
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
If (e.Url.ToString().StartsWith("https://www.weatherzone.com.au")) Then
WebBrowser1.Document.GetElementById("e").SetAttribute("value", "email@address.com")
WebBrowser1.Document.GetElementById("p").SetAttribute("value", "password")
WebBrowser1.Document.All().GetElementsByName("target").Cast(Of HtmlElement).First().InvokeMember("click")
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.WebBrowser1.Navigate("https://www.weatherzone.com.au/customise.jsp")
End Sub
To make the code more stable, add required null checkings.