Good day,

I'm tasked to develop an application that opens a web page, completes some fields to log on and then issues a crlf to send it on its way.

Here's the code

Public Sub LoginIntoSite(ByRef wbBrowser As SHDocVw.InternetExplorer)

    Dim HTMLDoc As mshtml.HTMLDocument
    Dim HTMLDoc2 As mshtml.HTMLDocument

    Do
    Loop Until Not wbBrowser.Busy

    HTMLDoc = wbBrowser.Document

    Dim iHTMLCol As IHTMLElementCollection
    Dim iHTMLEle As IHTMLElement
    Dim str As String

    iHTMLCol = HTMLDoc.getElementsByTagName("input")

    ' Type the user name in the username text box
    For Each iHTMLEle In iHTMLCol
                If Not iHTMLEle.getAttribute("name") Is Nothing Then
            str = iHTMLEle.getAttribute("name").ToString

            If str = "j_username" Then
                iHTMLEle.setAttribute("value", "admin")
                Exit For
            End If

        End If
    Next

    ' Type the password in the password text box
    For Each iHTMLEle In iHTMLCol

        If Not iHTMLEle.getAttribute("name") Is Nothing Then
            str = iHTMLEle.getAttribute("name").ToString

            If str = "j_password" Then
                iHTMLEle.setAttribute("value", "2)##SomePassword##")
                Exit For
            End If
        End If
    Next

So far so good if in weren't for the fact that it only runs when I step through the code manually. It would seem I need some mechanism to get the code to wait until it's safe to proceed.

The main problem I have is that after the password has been written to the correct field I need to pass an "Enter" or vbcrlf to submit the page. (The submit button is disabled, and the following code does not invoke any kind of a reaction )

 For Each iHTMLEle In iHTMLCol
        If Not iHTMLEle.getAttribute("name") Is Nothing Then
            str = iHTMLEle.getAttribute("name").ToString
            If str = "loginButton" Then

                iHTMLEle.setAttribute("Enabled", True)

                iHTMLEle.click()

                Exit For
            End If
        End If
    Next

Any help will be greatly appreciated!!!

Thanks

Hi
I suspect the web page you are inputting the data into is performing some sort of client side validation before enabling the submit button. So you are going to have to make your form wait until the button is enabled.

Before VB.Net we used to use Do Events but I believe the way .Net framework handles this is different now so you will have to use a Thread.Sleep call after you have inputted the data. This will block the current thread for the specified number of milliseconds.

Thank you, this worked fine!

Glad to be of help, remember to mark as solved...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.