View Single Post
  #1  
Old 07-08-2009, 12:03 PM
mmcgregor mmcgregor is online now
Registered User
 
Join Date: 07-08-2009
Posts: 5
Question VBScript/WScript issues hooking external application DOM events within VBPro 6.7a

Trying to respond to a created IE window/loaded form. Everything works great except for the limitation of hooking into the onclick of the form buttons and the other form/application messages like onquit. Anyway of making that work? Currently, when a button is pressed on the IE form, the button stays down (graphically stays pressed) and not events ever reach VBP script step.

Using VBP 6.7a on XP Pro OS fully service packed. Script engine is 5.7.

Any thoughts would be greatly appreciated.

The following script and HTML below work fine when launched from CScript or WScript at the command line. Within VBP 6.7a, the buttons just hang (stay depressed) when pressed and nothing happens (no msgboxes appear) in the script hooks within VBP step script.



Script used:
set ie = WScript.Createobject("internetexplorer.application ")
set shell = WScript.Createobject("WScript.Shell")

'Variables to control looping and waiting for user input
exitScript = false

'Turn off IE features. We want a bare IE window with just the required form
ie.MenuBar = false
ie.AddressBar = false
ie.StatusBar = false
ie.ToolBar = false

'Disallow popup dialogs
ie.Silent = true

'Show the explorer window.
ie.visible = true
shell.AppActivate(ie.Name)

'Set the page
html = "c:\input.html"
ie.navigate(html)

'Wait for the page to load
do while ie.readystate<>4
Loop

'Get access to IE's DOM to allow hooking to the buttons.
'This succeeds, but pressing the button currently hangs the button in the
' depressed state. No call ever happens in the VB code.
'This appears to possibly be related to the version of scripting and the
' inability to supply an alias in the VBPro WScript.CreateObject call.
set doc=ie.document
'Hook to the buttons to process functions here. Not working correctly
' when buttons are pressed
doc.forms(0).elements("Submit").onclick=getref("ie submit")
doc.forms(0).elements("Cancel").onclick=getref("ie cancel")

'Loop forever waiting until a button is pressed.
do while exitScript = false
WScript.Sleep(1000)
'builder.LogMessage "looping", true
loop

ie.Quit



'The submit button action; hook set above for onclick
Sub iesubmit()
MsgBox("Submit")
end sub

'The cancel button action; hook set above for onclick
Sub iecancel
MsgBox("Cancel")
exitScript = true
end sub





HTML (input.html):
<html>
<body>
<form method="get">
<input name="Test" value="Test" />
<BR>
<button name="Submit" value="Submit">Submit</button>
<button name="Cancel" value="Cancel">Cancel</button>
</form>
</body>
</html>
Reply With Quote