Where I work we have internal page that used to work with VBA, but I guess since last page or IE update it no longer does. Macro selects country and then press the button to generate a report for that particular country. Problem is that although the name in dropdown menu changes visually, the actual value does not change (onChange event is not being triggered). I have tried changing the .focus to another dropdown, firing/dispatching events, .SendKeys "~", but to no avail. This is what I have:
Dim document As HTMLDocument: Set document = ieTab.document
Dim processCnt As HTMLInputElement
Dim eventObj As Object
Dim hwndCounter As Integer
For i = 1 To 8
Set processCnt = ElementTimer(3, ieTab)
Select Case i
Case 1
processCnt.DefaultValue = "London"
Case 2
processCnt.Value = "Prague"
Case 3
processCnt.Value = "WUIB"
Case 4
processCnt.Value = "Zurich"
Case 5
processCnt.DefaultValue = "Norway"
Case 6
processCnt.Value = "Sweden"
Case 7
processCnt.Value = "Poland"
Case 8
processCnt.Value = "Russia"
End Select
Set eventObj = document.createEvent("HTMLEvents")
eventObj.initEvent "keyup", False, True
processCnt.dispatchEvent eventObj
Private Function ElementTimer(number As Integer, ieTab As InternetExplorer)
Dim messageBoxHW As LongPtr
On Error GoTo timer1
1:
Select Case number
Case 1
Set ElementTimer = ieTab.document.getElementsByClassName("rgNoRecords").Item(0)
Case 2
ieTab.document.getElementById("gvReport_ctl00_ctl02_ctl00_ExportToExcelButton").Click
Case 3
Set ElementTimer = ieTab.document.getElementById("ProcessCenter_ID_Input")
If ElementTimer Is Nothing Then GoTo timer1
End Select
On Error GoTo 0
Exit Function
timer1:
DoEvents
messageBoxHW = FindWindow(vbNullString, "Message from webpage")
If messageBoxHW > 0 Then SendMessage messageBoxHW, WM_CLOSE, 0, 0
Resume 1
End Function
The value is being changed before this code. This is the drop-down Im having problems with.
<!-- 2020.3.1021.45 --><table summary="combobox" border="0" style="border-width:0;border-collapse:collapse;width:100%" class="rcbFocused rcbExpanded">
<tbody><tr class="rcbReadOnly">
<td class="rcbInputCell rcbInputCellLeft" style="width:100%;"><input name="ProcessCenter_ID" type="text" class="rcbInput radPreventDecorate" id="ProcessCenter_ID_Input" value="United States" readonly="readonly" autocomplete="off"></td><td class="rcbArrowCell rcbArrowCellRight"><a id="ProcessCenter_ID_Arrow" style="overflow: hidden;display: block;position: relative;outline: none;">select</a></td>
</tr>
</tbody></table><input id="ProcessCenter_ID_ClientState" name="ProcessCenter_ID_ClientState" type="hidden" autocomplete="off">
</div>
Does this mean that you can no longer simulate change events? Because it sure looks like it after 2 days of googling and trying. Im out of ideas
"Copy JS Path" yielded this: document.querySelector("#ProcessCenter_ID")
To be honest I don't know how to identify the exact JS that is being initiated upon changing the value of a drop-down
readonly
attribute in the<input>
which means you can't edit it. You can also try to remove thereadonly
attribute to see if this can fix the issue.onchange
event. You can refer to this article about dispatching theonchange
event. Please pay attention to that it should be objEvent.initEvent "change", True, False.