【问题标题】:Excel VBA - Two IE popups with same titleExcel VBA - 两个具有相同标题的 IE 弹出窗口
【发布时间】:2021-01-15 11:02:10
【问题描述】:

我正在编写 IE 的 VBA 自动化。应用程序正在寻找特定的票号并尝试将其分配给用户。单击网页上的按钮后,在某些情况下,它可能会返回最多两个警报,两个警报都具有相同的窗口标题(“来自网页的消息”),需要按 OK 按钮。

我能够捕捉到第一个弹出窗口,但无法处理第二个弹出窗口。我认为处理这个问题的最好方法是从这些弹出窗口中阅读消息,但我不知道如何做到这一点。似乎两个 wscript 都在捕获第一个弹出窗口,并且无法检测到第二个弹出窗口。请问您能帮忙吗?

我尝试了以下方法,但没有运气:


            '' If ticket was found and is not assigned to any user, run script to handle popup
            If sBut(currentPos + 11).innerHTML <> currentUser Then
                pid = Shell("wscript.exe ""pathToScript\msgClick.vbs""")
            End If

                pid2 = Shell("wscript.exe ""pathToScript\itemClaimed.vbs""")
                zBut = sBut(currentPos + 13).getElementsByTagName("input")
                zBut.Click

一旦单击 zBut 并且两个弹出窗口都出现,脚本只处理第一个,第二个保持不变。

下面是 msgClick.vbs 的代码(和 itemClaimed.vbs,两者都是相同的 - 我认为运行两个单独的文件会有所帮助)

Set wshShell = CreateObject("WScript.Shell")

Do
    windowLookUp = wshShell.AppActivate("Message from webpage")
    
Loop Until windowLookUp = True
    WScript.sleep 500
    windowLookUp = wshShell.AppActivate("Message from webpage")
    If windowLookUp = True then
        windowLookUp = wshShell.AppActivate("Message from webpage")
        WScript.Sleep 10
        wshShell.SendKeys "{enter}"
    end if

【问题讨论】:

    标签: excel vba internet-explorer vbscript


    【解决方案1】:

    我傻了。 不是从 VBA 运行两个脚本,而是可以从 VBA 启动一个,另一个在第一个脚本执行后启动。像魅力一样工作。

    Set wshShell = CreateObject("WScript.Shell")
    
    Do
        windowLookUp = wshShell.AppActivate("Message from webpage")
        
    Loop Until windowLookUp = True
        WScript.sleep 500
        windowLookUp = wshShell.AppActivate("Message from webpage")
        If windowLookUp = True then
            windowLookUp = wshShell.AppActivate("Message from webpage")
            WScript.Sleep 10
            wshShell.SendKeys "{enter}"
            
            dim objShell
            Set objShell = Wscript.CreateObject("WScript.Shell")
            objShell.Run "pthToScript\itemClaimed.vbs"
            
            Set objShell = Nothing
        end if
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-03
      • 2021-10-30
      • 2020-02-20
      • 1970-01-01
      • 1970-01-01
      • 2023-02-21
      • 2020-04-05
      • 1970-01-01
      相关资源
      最近更新 更多