Hi all,
I’m currently using WIN32OLE object to test my Web pages. What I need to
do is to trigger HTML event on specific element with the event object I
pass to the fireEvent() method. But unfortunately, I’m not able to make
it work.
Here’s the HTML file(c:\test.html, will be used in the following code):
testHere’s the Ruby code I’m using:
require ‘win32ole’
ie = WIN32OLE.new(‘InternetExplorer.Application’)
ie.visible = TRUE
ie.gohome
ie.navigate(‘c:\test.html’)
event_obj = ie.document.createEventObject
event_obj.keycode = 1
ie.document.body.fireEvent(‘onkeyup’,event_obj)
print “Now quit Internet Explorer… Please enter.”
gets
ie.Quit()
The result expected is the popping up an alert window whose content is
1, which is the value of the keycode property of the event object passed
in. But the actual result is the value becomes ‘undefined’. If I use
Javascript to implement the same logic, it works as expected.
Here’s code of Javascript:
var e = document.createEventObject();
e.keycode = 1
document.body.fireEvent(‘onkeyup’,e);
Does anybody know the reason why the event object created cannot be got
by the browser? Any advice would be appreciated. Thanks a lot.
-Derek