41. Website Login

In this tutorial, we cover how to log into a website by interacting with HTML elements in a page using the element ID. Don’t worry if you don’t quite understand it yet, there are a few more tutorials that will explain it in more depth. Interacting with HTML elements is a good way to create a bot that will automate web page tasks.

Code

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        WebBrowser1.Navigate("http://login.yahoo.com/")
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        WebBrowser1.Document.GetElementById("login").SetAttribute("value", TextBox1.Text)
        WebBrowser1.Document.GetElementById("passwd").SetAttribute("value", TextBox2.Text)

        WebBrowser1.Document.GetElementById(".save").InvokeMember("click")
    End Sub

End Class