Hello,
I am working on a personal project to make my life easier.
I am automating a javascript web form submission process using webbrowser.
I would like to use something without a UI but don't think httpresponse etc would do all that is needed at a newbie level of understanding.

My code works but I think is not designed correctly. I think I should be breaking each step into its own sub or function.

In its current state I think every time a page is refreshed/redrawn all the code is running which makes causes endless looping of clicking a link which is on its own destination page. What that means is click the link and the page refreshes with new information but does not navigate to a new page. So the code looks for the link and selects it over and over and over .... This I think needs to be subbed or done as a function instead.

Here's the code. Please suggest or give guidance with specific examples (I am a newbie and only touch programming once a year or so.)

Thanks in advance

Code:
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Part 1: Load elogging login page in Form_Load event  
        WebBrowser1.Navigate("https://www.somesite.com/elog/login.do")
    End Sub

    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        'Part 2: Locate the Username TextBox and automatically input your username  
        '<INPUT class=yreg_ipt id=username maxLength=96 size=17 name=login> 
        Dim clicked As Integer
        clicked = 0
        Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")
        For Each curElement As HtmlElement In theElementCollection
            Dim controlName As String = curElement.GetAttribute("name").ToString
            If controlName = "userId" Then
                curElement.SetAttribute("Value", "User_name")
            End If
        Next

        'Part 3: Locate the Password TextBox and automatically input your password  
        '<INPUT class=yreg_ipt id=passwd type=password maxLength=64 size=17 value="" name=passwd>  
        theElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")
        For Each curElement As HtmlElement In theElementCollection
            Dim controlName As String = curElement.GetAttribute("name").ToString
            If controlName = "passwd" Then
                curElement.SetAttribute("Value", "password")
            End If
        Next

        'Part 4: Locate the "Sign In" Button and automatically click it  
        theElementCollection = WebBrowser1.Document.GetElementsByTagName("a")
        For Each curElement As HtmlElement In theElementCollection
            If curElement.GetAttribute("href").Equals("javascript:doLogin()") Then
                curElement.InvokeMember("click")
                'Javascript has a click method for we need to invoke on the current submit button element.  
            End If
        Next

        Dim navigateurl = WebBrowser1.Url.ToString
        MsgBox(navigateurl)

        'Part 5: Locate the "View Case" link and automatically click it  
        For Each curElement As HtmlElement In theElementCollection
            Dim controlText As String = curElement.GetAttribute("InnerText").ToString
            If controlText = "View Support Request" Then
                'Dim url As String = curElement.GetAttribute("href")
                clicked = clicked + 1
                If (clicked < 2) Then
                    curElement.InvokeMember("click")
                    ' Click the hyperlin
                End If
            End If
        Next

        'Part 6 locate the support request ID text box and enter in case number
        theElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")
        For Each curElement As HtmlElement In theElementCollection
            Dim controlName As String = curElement.GetAttribute("name").ToString
            If controlName = "caseId" Then
                curElement.SetAttribute("Value", "C455603")
            End If
        Next

        'Part 7 search for the case
        theElementCollection = WebBrowser1.Document.GetElementsByTagName("a")
        For Each curElement As HtmlElement In theElementCollection
            If curElement.GetAttribute("href").Equals("javascript:doSearch()") Then
                curElement.InvokeMember("click")
                'Javascript has a click method for we need to invoke on the current submit button element.  
            End If
        Next

        'Part 8: Locate the "View Case" link and automatically click it  
       theElementCollection = WebBrowser1.Document.GetElementsByTagName("a")
        For Each curElement As HtmlElement In theElementCollection
            If curElement.GetAttribute("href").Equals("javascript:doDetails(0)") Then
                curElement.InvokeMember("click")
                'Javascript has a click method for we need to invoke on the current submit button element.  
            End If
        Next



    End Sub

End Class