-1

I am on this site.

https://brokercheck.finra.org/

I am trying to use VBA to place a number into the first box ("Name or CRD#") and press search. I cannot figure out how go the information in the box.

Here is the HTML code (sorry if there is not enough) which is why I provided the link.

> div layout-gt-xs="row" layout-xs="column" layout-align-xs="space-between center" class="layout-xs-column layout-gt-xs-row layout-align-xs-space-between-center"


>input type="text" ng-model="searchCtrl.name" placeholder="Name or CRD#" flex="auto" class="ng-pristine ng-valid flex-auto ng-empty ng-touched" aria-invalid="false" style=""

My code so far is this:

Sub BrokerCheckSlim()

Dim objIE As InternetExplorer 'special object variable representing the IE browser
Set objIE = New InternetExplorer 'Creates IE object
objIE.Visible = True 'Can you see the browser?
objIE.navigate "https://brokercheck.finra.org/" 'Open Website
Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop 'Keeps CPU from crashing

objIE.document.getElementsByClassName("ng-pristine ng-valid flex-auto ng-empty ng-touched").Item(0).Value = 1
objIE.document.getElementById("firm-input").Value = 1
objIE.document.getElementsByClassName("md-raised md-primary md-hue-2 md-button md-ink-ripple").Item(0).Click

Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop

End Sub

Any help would be appreciate.

Thanks

jsotola
  • 2,238
  • 1
  • 10
  • 22
Connor R.
  • 1
  • 1
  • Where are you stuck? Did you use Firefox to inspect items? Some elements can change class in run-time. – PatricK Dec 13 '17 at 22:32
  • 1
    Your code looks good, but it doesn't work because the website is full of AngularJS and some validation is done on user action. If you observe the HTML document while you type a value in your input box, you will see a lot of properties updating (not only on the input but also on the form). One of them must be controlling the form from executing directly from client side (to avoid useless calls on server): if the input isn't valid, the client blocks your execution without even going to server. Your problem is that just setting the value of the box doesn't make the form valid for that website. – Matteo NNZ Dec 13 '17 at 22:33
  • P.s. make your question clearer (I had to run your code to understand your issue). P.p.s. the solution lies on observing the HTML on manual actions and find what is that property of the form making it valid to go to the server (then your code should work). – Matteo NNZ Dec 13 '17 at 22:35
  • Thanks Matteo. I was able to find a work around. Do you have any suggestions to help automate this if I come across it again in the future? – Connor R. Dec 14 '17 at 15:15

2 Answers2

0

found this info Entering data using VBA in to a HTML5 site

this code fills in the field and clicks on the button

press F5 to continue from stop

Option Explicit

' found info here https://stackoverflow.com/questions/33667426/entering-data-using-vba-in-to-a-html5-site

Sub BrokerCheckSlim()

    Dim objIE As InternetExplorer                                           ' object variable representing the IE browser
    Set objIE = New InternetExplorer                                        ' instantiates IE object

    objIE.Visible = True                                                    ' make browser visible
    objIE.navigate "https://brokercheck.finra.org/"

    Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop     ' service other events while web page loads

    objIE.document.getElementsByClassName("ng-pristine ng-untouched ng-valid flex-auto ng-empty").Item(0).Focus
    objIE.document.getElementsByClassName("ng-pristine ng-untouched ng-valid flex-auto ng-empty").Item(0).innertext = "smith"

    With objIE.document.getElementsByClassName("md-raised md-primary md-hue-2 md-button md-ink-ripple").Item(0)  ' using the "with" statement to refer to objects
        .Focus
        .Click
    End With

'   objIE.document.getElementById("firm-input").Value = 1

'   Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop

    Stop                ' press F5 of F8 to continue

    objIE.Quit
    Set objIE = Nothing

End Sub
jsotola
  • 2,238
  • 1
  • 10
  • 22
0

As compound class names are not always good landmarks to pursue, I tried to make the scraper slightly differently. The below script will let you enter that name in the first search-box and press the click button. Give it a go:

Sub BrokerCheckSlim()
    Dim IE As New InternetExplorer, html As HTMLDocument
    Dim post As Object, elem As Object

    With IE
        .Visible = True
        .navigate "https://brokercheck.finra.org/"
        Do Until .readyState = READYSTATE_COMPLETE: Loop
        Set html = .document
    End With

    For Each post In html.getElementsByTagName("input")
        If InStr(post.placeholder, "Name or CRD#") > 0 Then
            post.Focus
            post.innerText = "martin": Exit For
        End If
    Next post

    For Each elem In html.getElementsByTagName("button")
        If InStr(elem.Type, "submit") > 0 Then elem.Click
    Next elem
    IE.Quit
End Sub
SIM
  • 21,997
  • 5
  • 37
  • 109