2+ years ago I asked basically this same question (Automate IE via Excel to fill in a dropdown and continue) and it worked perfectly until a couple of months ago. The code that I previously used is below:
Private Sub TriggerEvent(htmlDocument As Object, htmlElementWithEvent As Object, eventType As String)
Dim theEvent As Object
htmlElementWithEvent.Focus
Set theEvent = htmlDocument.createEvent("HTMLEvents")
theEvent.initEvent eventType, True, False
htmlElementWithEvent.dispatchEvent theEvent
My Web Scraping code is below:
Private Sub SelectDropDown()
ForceIEClose
Set ie = CreateObject("InternetExplorer.Application")
With ie
.navigate "https://a810-dobnow.nyc.gov/publish/Index.html#!/"
.Visible = True ' can be set to false to speed things up
End With
Do Until ie.readyState = 4: DoEvents: Loop
Set htmlDoc = ie.document
'htmlDoc.getElementsByClassName("white ng-scope")(3).Click ' {Device Search} button
' New: "Search by device type"
htmlDoc.getElementsByClassName("card border-tiles shadow h-100 padY-2 device-off")(0).Click ' {Device Search} button
On Error Resume Next
Set nodeDeviceTypeDropdown = htmlDoc.getElementById("DeviceOptions") ' {Device Type} DropDown
Application.Wait (Now + TimeSerial(0, 0, 1))
On Error GoTo 0
If Not nodeDeviceTypeDropdown Is Nothing Then
nodeDeviceTypeDropdown.selectedIndex = 4
To this point everything works fine and the 4th option on the drop-down is displayed on the page. What's not working now is the following line of code:
Call TriggerEvent(htmlDoc, nodeDeviceTypeDropdown, "change")
I have tried just about everything imaginable in place of that "change" but nothing seems to work to indicate within IE that I've made my selection which would normally display the next drop-down that I need to work with?? The HTML code for the drop-down object is below:
<select required="" class="form-control ng-pristine ng-empty ng-invalid ng-invalid-required ng-touched" id="DeviceOptions" ng-model="Criteria.DeviceOptions" ng-class="{'has-error': (IsDeviceSearchClick && !Criteria.DeviceOptions)}">
<option class="selectPlaceholder" name="device" value="" hidden="" selected="selected">Select Device Type</option>
<option value="1">Boilers</option>
<option value="2">Elevator</option>
<option value="3">Crane Prototype</option>
<option value="4">Crane Device</option>
</select>
I'm not sure exactly what changed from before that stopped this from working. Any ideas on how to make this work would be appreciated. Thanks.
Original HTML Code that worked with my current vba shown below: