VBScript IE automation - Pressing "Ok" on a Confirm Popup
I'm automating a web application. I can currently get the webpage to enter some info into a form and press a Submit button. However, the page requires a confirmation prior to submit the form. It calls the confirm() function which pops-up a small window with Ok or Cancel. I want to automate the clicking of 'Ok'.
开发者_StackOverflow社区It doesn’t work with SendKeys, because when the confirm() popup function is called, the Wscript seems to pause & wait for the confirmation (Ok or Cancel) before continuing.
My code is attached below:
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.Navigate "www.abc.com"
Do While objIE.Busy Or (objIE.READYSTATE <> 4)
Wscript.Sleep 100
Loop
objIE.Document.all(73).value = "Testing…" 'this is the form input
objIE.Document.all(106).click 'this is the submit button
'Confirm box will come up here & I want to press 'Ok'
***'Something in here to press the popup Ok button???***
Thanks a lot!
Simple but not totally fail proof solution: Just before the click, startup a new VBScript file through the WSH with a 1 second wait and a sendkey "{ENTER}"
action in it.
The following is certainly not fail proof either.
Can you click the submit button using SendKeys
instead of objIE.Document.all(106).click
?
If so, then you could try sending two keys in a row, i.e. SendKeys "{ENTER}{ENTER}"
(or whatever two keys are required in each case).
If not, then you could try sending SendKeys "{ENTER}"
before clicking the submit button using objIE.Document.all(106).click
(after making sure that no field is selected). In some cases, the sent key is kept in memory until such time where it is applicable.
You can try this:
objIE.Document.all.item("106").click
It find the item and click it.
精彩评论