Input text in Internet Explorer (Username/password)

blacktour

Board Regular
Joined
May 24, 2005
Messages
219
Hi,

This was working on another website, but I can't get it to work now. Trying to input username/password on this site and click submit.

<code>

Sub PLineBot()
Dim IE As Object
Dim url As String


Set IE = CreateObject("internetexplorer.application")
IE.Visible = True
url = "https://propertyline.ca/"
IE.navigate url

'wait for page to load
Do
DoEvents
Loop Until IE.readyState = 4


IE.document.getElementById("account").Value = "username"
IE.document.getElementById("password").Value = "password"

IE.document.forms(0).submit.Click

End Sub

</code>

Any ideas?
 

blacktour

Board Regular
Joined
May 24, 2005
Messages
219
Again, appreciate your help. It goes without saying, without people like you on here, this stuff would be impossible for most of us.

The internals of the site react strange. With the script I am able to login and enter text in the text box.

However, if there is not a keyboard input the search button does not even react. It won't produce any results, even if the script adds the text to the search field and you manually click search nothing happens.

If you just click in the search field and hit space after the search criteria it works right away. Not sure how to overcome this. I probably didn't even explain it well.

Here is my code:

Code:
Option Explicit

Sub Test()

Dim timeout As Date
Dim IE As Object
Dim PW As Object
Dim my_url As String

' open IE, navigate to the desired page and loop until fully loaded
    Set IE = CreateObject("InternetExplorer.Application")
    my_url = "https://www.reports.propertyline.ca/login" 'used this instead of main scree to avoid having to deal with the frames
    
    With IE
        .Visible = True
        .navigate my_url

    Do Until Not IE.Busy And IE.readyState = 4
        DoEvents
    Loop

    End With
    
    Set PW = IE.document.getElementById("account")
    PW.Value = "account"

    Set PW = IE.document.getElementById("password")
    PW.Value = "password"
       
' Click the "Submit" button
    IE.document.getElementById("submit").Click
'

    timeout = Now + TimeValue("00:00:3")
    Application.Wait (timeout)
    
    'enter roll number
    Set PW = IE.document.getElementById("search_arn")
    PW.Value = "061430081008790"
    
        'enter roll number
    Set PW = IE.document.getElementById("multiArnList")
    PW.Value = "061430081008790"
    PW.Focus
    
    
    Set PW = IE.document.getElementsByClassName("btn btn-xs-md btn-1-blue")(1)
    PW.Click

The HTML from the website is:

Code:
Code for search box:

input type="text" class="form-control" data-bind="value: arn, events: { keydown: arnKeyDown, keyup: arnKeyUp }" id="search_arn">

Code for search button:

a href="#" class="btn btn-xs-md btn-1-blue" data-bind="click: arnSearch">Search</a>

Thanks!
 
Last edited:

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

blacktour

Board Regular
Joined
May 24, 2005
Messages
219
Ok so I am almost there, only 2 buttons left to click, and yet again I am stuck at an odd button. I resorted to using this to click all the buttons to this point:

Code:
    Set PW = IE.document.getElementsByTagName("a")(29)
    PW.Focus
    PW.Click

It seems I can't use this to click this button:

Code:
button class="btn btn-xs-md btn-1-blue action view" pid="88">View</button>

Any way to use that "pid=88" number?

Thanks!!
 

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
7,052
I registered as a guest account and see what you mean about the Roll Number input box. As shown by the HTML you posted, it uses events to trap keyboard input and start the search, however I've not been able to replicate these in VBA. For example:
Code:
Private Sub rollInput1(HTMLdoc As HTMLDocument)
    
    Dim eventObj As IDOMEvent
    Dim rollInput As HTMLInputElement
    Dim rollNumber As String
    
    rollNumber = "061430081008790"
    
    Set eventObj = HTMLdoc.createEvent("HTMLEvents")
    eventObj.initEvent "change", True, False
    
    '< input class="form-control" id="search_arn" type="text" data-bind="value: arn, events: { keydown: arnKeyDown, keyup: arnKeyUp }">

    Set rollInput = HTMLdoc.getElementById("search_arn")
    rollInput.Focus
    rollInput.Value = rollNumber
    rollInput.dispatchEvent eventObj

End Sub
I also tried populating the input box character by character in a loop - rollInput.Value = rollInput.Value & Mid(rollNumber, i, 1) - firing the event for each character, and also the VBA SendKeys function to populate the input box character by character.

For the View button, you could look for a button with innerText = "View" or "pid" attribute = "88", like this:
Code:
    Dim HTMLdoc As HTMLDocument
    Dim buttons As IHTMLElementCollection
    Dim viewButton As HTMLButtonElement
    Dim i As Long
    
    Set buttons = HTMLdoc.getElementsByTagName("BUTTON")
    i = 0
    Set viewButton = Nothing
    While i < buttons.Length And viewButton Is Nothing
        'Either
        If buttons(i).innerText = "View" Then Set viewButton = buttons(i)
        'Or
        'If buttons(i).getAttribute("pid") = "88" Then Set viewButton = buttons(i)
        i = i + 1
    Wend
    
    If Not viewButton Is Nothing Then
        viewButton.Click
    End If
All the above code requires a reference to MS HTML Object Library in Tools -> References in the VBA editor.
 

Forum statistics

Threads
1,144,528
Messages
5,724,854
Members
422,585
Latest member
k3n

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top