Reputation: 95
I have the following abridged code to navigate to a webpage and fill a search box. However, I cannot understand how to fill the search box, given the classname is embedded in an input element. Please let me know if you have any insight. Thanks.
Dim ie, results As Object
Dim pagenumber, pagetotal, r, s As Long
Dim finrawebpage As HTMLDocument
Dim searchterm As HTMLElementCollection
Dim i As Integer
Set ie = CreateObject("InternetExplorer.application")
brokersearch = InputBox("ENTER BROKER NAME OR CRD#")
'firmsearch = InputBox("ENTER FIRM NAME OR CRD#")
'geosearch = InputBox("ENTER CITY, STATE, OR ZIP")
Application.StatusBar = "LOADING FINRA SEARCH"
With ie
.Visible = True
.navigate "https://brokercheck.finra.org/"
Do While .busy Or _
.readystate <> 4
DoEvents
Loop
Set finrawebpage = ie.document
'Set searchterm = finrawebpage.getElementsByTagName("input")
'i = 0
'While i < searchterm.Length
'If searchterm(i).Type = "text" Then
'searchterm(i).Value = brokersearch
'Set searchterm = finrawebpage.getElementsByClassName("ng-pristine ng-scope ng-empty ng-valid ng-valid-required ng-touched")
'If searchterm.Length > 0 Then
'searchterm(0).Value = brokersearch
'End If
finrawebpage.getElementsByClassName("ng-pristine ng-scope ng-empty ng-valid ng-valid-required ng-touched").Item.Value = brokersearch
'finrawebpage.getElementsByClassName("searchAutoContainer flex-auto").Item.innertext = brokersearch
'finrawebpage.getElementsByClassName("md-raised md-primary md-hue-2 md-button md-ink-ripple").Item.Click
'Wend
End With
End Sub
Upvotes: 0
Views: 149
Reputation: 1
It looks like you were on the right track based on the commented lines in your code. Try:
Do While i < ie.document.getElementsByTagName("input").length
If ie.document.getElementsByTagName("input")(i).getAttribute("placeholder") = "Name or CRD#" Then
ie.document.getElementsByTagName("input")(i).value = brokersearch
End If
Loop
This will eliminate the need to hard code the position of the element which has a good chance of breaking if they update the page frequently. That isn't to say keying off the placeholder is perfect, but your options are limited based on what I saw on the page.
Upvotes: 0