开发者

Using a WindowsXP VBScript to automate Internet Explorer, how can I 'click ok' when a dialog box appears?

开发者 https://www.devze.com 2022-12-28 22:51 出处:网络
My Windows VBScript opens an InternetExplorer.Application object, and runs through some navigation.At one point the page I\'m working with displays a dialog box in which I must 开发者_如何学Cclick \"O

My Windows VBScript opens an InternetExplorer.Application object, and runs through some navigation. At one point the page I'm working with displays a dialog box in which I must 开发者_如何学Cclick "OK" or "Cancel." Is there a way to tell the VBScript to click "OK" when the dialog box pops up?


VBScript isn't very good at dealing with GUI functions, at least, it is not even remotely close to something like AutoIT; anyway, that said there is a sendkeys function in VBScript, but the problem is that you can't do an "on event" type of call, you basically have to use a timer, so it really isn't a good solution, but as far as I know it's all you've got, at least natively to VBS.

So maybe you could kick off your IE object, then throw in a wait timer and then sendkeys. WAY hokey... but it could work.

Here's the MSDN article on sendkeys with examples.


If all you want is to close a dialog box, this may help you:

Set oShell = CreateObject("WScript.Shell") 

Do 
    bResult = oShell.AppActivate("Title of the dialog box") 
    If bResult = True Then 
        oShell.SendKeys "{Enter}" 
        ' or "%K" for Alt+k, for OK and "%N" (Alt+N) for Cancel
        Exit Do 
    End If 
    WScript.Sleep 500 
Loop 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号