0

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

5
  • Is there any error when it doesn't work? Could you please provide the complete related code with the dropdown menu so that we can have a test? Besides, I noticed that there's a readonly attribute in the <input> which means you can't edit it. You can also try to remove the readonly attribute to see if this can fix the issue.
    – Yu Zhou
    Commented Feb 10, 2021 at 3:17
  • I've added the code that selects value from drop-down. Any ideas how to initiate that change event?
    – Radas
    Commented Feb 10, 2021 at 12:45
  • It seems that there's some misunderstanding. I mean the related html and javascript code about the dropdown menu. It's an internal page and we can't have a test with a link. So I want to check the html structure and check how the event is fired in the original page.
    – Yu Zhou
    Commented Feb 11, 2021 at 8:37
  • I've added to the original question, but I dont think it will be of any help since I can not identify the script that is being called once the changes are made.
    – Radas
    Commented Feb 11, 2021 at 15:06
  • You're right. It seems nothing special with the html code. It's hard to debug without having access to the website. I can only provide some information about firing onchange event. You can refer to this article about dispatching the onchange event. Please pay attention to that it should be objEvent.initEvent "change", True, False.
    – Yu Zhou
    Commented Feb 17, 2021 at 6:55

0

Browse other questions tagged or ask your own question.