How to pass the login information to a webpage and login automatically RRS feed

  • Question

  • Hi All,

    I would like to automate a below task.

    We have intranet web portal, session times out in each 5 minutes. I would like to create an exe file using Visual Basic, on executing it should open the intranet web portal in IE with automatic feed in of login ID and Password then login.

    I have tried below code but didn't work. Could you assist on this.

    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

            WebBrowser1.Document.GetElementById("USERNAME").SetAttribute("value", "xxxxxx")
            WebBrowser1.Document.GetElementById("PIN").SetAttribute("value", "xxxxx")
        End Sub

        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            WebBrowser1.Document.GetElementById("USERNAME").SetAttribute("value", "xxxxx")
            WebBrowser1.Document.GetElementById("PIN").SetAttribute("value", "xxxxx")
        End Sub
    End Class

    Saturday, April 29, 2017 11:54 AM

All replies

  • You should wait until DocumentCompleted has triggered then run your code. So Navigate("") in say form load or a button click event then run the search for elements and invoke in DocumentCompleted event.

    Private Sub WebBrowser1_DocumentCompleted(
    sender As Object, e As WebBrowserDocumentCompletedEventArgs) _
    Handles WebBrowser1.DocumentCompleted
        ' once this event has been triggered you 
        ' can search for the elements with the 
        ' identifiers of USERNAME and PIN
        ' then issue InvokeMember
        Dim userNameElement = WebBrowser1.Document.GetElementById("USERNAME")
        Dim userPinElement = WebBrowser1.Document.GetElementById("PIN")
        Dim loginElement = WebBrowser1.Document.GetElementById("login")
        If userNameElement IsNot Nothing AndAlso userPinElement IsNot Nothing Then
            userNameElement.SetAttribute("", "")
            userPinElement.SetAttribute("", "")
            If loginElement IsNot Nothing Then
            End If
        End If
    End Sub

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Saturday, April 29, 2017 12:55 PM
  • Prasad,

    Be aware there is not one Login method on the Web. Here some in a webpage.

    ASP.Net uses the IIS way while the old way was the easy W3C way which we don't see anymore.

    therefore first find out what authentication is used otherwise you can be busy 100 years. 


    Sunday, April 30, 2017 6:02 PM