Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

catching an event in VBScript

guys. This is a VBS script that opens google, fills a form, and clicks a search button.

set ie = CreateObject("InternetExplorer.Application")

ie.navigate("www.google.com")

ie.visible = true

while ie.readystate <> 4
    wscript.sleep 100
WEnd

set fields = ie.document.getelementsbyname("q")
set buttons = ie.document.getelementsbyname("btnG")

fields(0).value = "some query"
buttons(0).click

ie.quit

Sub OnClickSub()
    MsgBox  "button clicked!", 0
End Sub

Obviously, buttons(0).click fires an onclick event of the button, which I somehow need to catch in my script, and provide it with some processing like launching OnClickSub().

Has anyone got any ideas how this should be done?

like image 634
Kirill Leontev Avatar asked Feb 13 '26 18:02

Kirill Leontev


1 Answers

Use the GetRef function to obtain a pointer to your event handler and bind it to the onclick event, like this:

buttons(0).onclick = GetRef("OnClickSub")

(Apparently, attachEvent doesn't work when called from outside the web page.)

like image 108
Helen Avatar answered Feb 16 '26 17:02

Helen