当IE模式弹出窗口出现时,VBscript自动化脚本卡住了

时间:2015-12-01 12:39:10

标签: vbscript

我使用vbscript使用IE自动化网站操作。 在一个地方,单击按钮可创建模态弹出窗口。当弹出窗口出现时,脚本不会进一步执行并冻结。

我想过执行第二个脚本,但我无法激活弹出窗口。弹出对话框的标题为“Proceed - Webpage Dialog”,以及2个按钮 - Ok和Cancel。我正在使用以下代码激活弹出窗口,然后单击“确定”。但是我无法抓住窗户。下面是第二个脚本的代码。

script2.vbs:

WScript.Sleep 5000

Msgbox "Started 2nd script"

For Each wnd In CreateObject("Shell.Application").Windows
    If InStr(1, wnd.FullName, "iexplore.exe", vbTextCompare) > 0 Then
        If InStr(1, wnd.Document.Title, "Proceed", vbTextCompare) > 0 Then
            Set objIE = wnd
            MsgBox "Found Window"
            Exit For
        End If
    End If
Next

这没什么,我也不知道如何处理这个弹出窗口。对此有任何想法或解决方法,将会非常有帮助。

更新

以下是主脚本的代码。

script1.vbs:

Dim url
url = "http://example.com"

Set objIE = CreateObject("InternetExplorer.Application")
Set WshShell = WScript.CreateObject("WScript.Shell") 
objIE.Visible = True
objIE.AddressBar = True
objIE.StatusBar = False
objIE.MenuBar = True

WshShell.AppActivate ("Internet Explorer")
objIE.Navigate url

'''
'   Some code to perform website operations 
'
'

WshShell.Run "script2.vbs"

''The below line triggers the popup
Set btn = objIE.Document.GetElementById("grayBtn").GetElementsByTagName("a").Item(0)
btn.Click

0 个答案:

没有答案