Reputation: 11
I'd like to click on "OK" to a popup javascript question.
Here is my html file (c:\temp\test.html):
<HTML>
<HEAD>
<SCRIPT LANGUAGE="javascript">
confirm( "Please click OK" );
</SCRIPT>
</HEAD>
</HTML>
and here is the starting of a basic vbs file to open the html file (c:\temp\test.vbs) :
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate ("file:///C:/temp/test.html")
How to click on the "Ok" button by completing the vbs file?
Edit : The html cannot be changed cause he's from a robotic hardware and the manufacturer don't allow anykind of change in their code (the .html sample code in my post is just an exemple of what kind of msgbox they use)
the "sendkey" option is a good alternative, but in my case i cannot do this on the server. the vbscript is a long harder than the vbscript i've post, and in experience the "sendkey" option does not give 100% exact result (if the msgbox does not displayed and i sendkey "enter", it can do critical stuffs). i'm going more in that kind of command line : ie.Document.all.Item("Ok").Click , but i didn't find an alternative for javascript "confirm" msgbox type.
Upvotes: 1
Views: 2509
Reputation: 1702
The way you would do this would either be by using SendKeys or by using a different type of "confirm" box.
SendKeys, put this after the IE.Navigate
:
Set objShell = CreateObject("Wscript.shell")
objShell.AppActivate("c:\temp\test.html")
WScript.Sleep 100
objShell.SendKeys "{ENTER}"
Different type of confirm:
add this to the .html
<input type="submit" id="Confirmed" value="Yes" onClick="runConfirmCode">
<input type="button" id="NotConfirmed" value="No" onClick="runNotConfirmedCode">
then in the .vbs add this after IE.Navigate
IE.Document.getElementByID("Confirmed").click
Upvotes: 1