IE11 是否仍然支持 dispatchEvent/FireElement?

时间:2021-02-09 13:50:53

标签: vba internet-explorer-11

在我工作的地方,我们有用于使用 VBA 的内部页面,但我想自上一页或 IE 更新以来,它不再适用。 宏选择国家,然后按下按钮生成该特定国家的报告。问题是,虽然下拉菜单中的名称在视觉上发生了变化,但实际值并没有改变(没有触发 onChange 事件)。我曾尝试将 .focus 更改为另一个下拉列表、触发/调度事件、.SendKeys "~",但无济于事。 这就是我所拥有的:

    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

此代码之前的值正在更改。 这是我遇到问题的下拉菜单。

            <!-- 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>

这是否意味着您不能再模拟变更事件?因为经过 2 天的谷歌搜索和尝试,它确实看起来像它。我没有想法

“复制 JS 路径”产生了这个:document.querySelector("#ProcessCenter_ID")

老实说,我不知道如何识别更改下拉列表值时正在启动的确切 JS

0 个答案:

没有答案