Hello. I got a little problem while using pythoncom to automate IE; for
some reason, changing the 'selectedIndex' on an instance of
IHTMLSelectElement doesn't fire the 'onchange' event (I guess this is a
bug in mshtml).
So, I tried to get the 'onchange' event handler and call it myself.
According to the docs, this is a simple IDispatch implementation and
calling Invoke() should do the trick; I actually have a working example
of this in Delphi.
But I can't manage to get it work in Python; the following code
idisp = pythoncom.WrapObject(elt.onchange)
idisp.Invoke(pythoncom.DISPID_VALUE,
0x400, # LOCALE_USER_DEFAULT
pythoncom.DISPATCH_METHOD,
False)
fails with an AttributeError:
Traceback (most recent call last):
File "C:\Python22\Lib\site-packages\win32com\server\policy.py", line
283, in _
Invoke_
return self._invoke_(dispid, lcid, wFlags, args)
File "C:\Python22\Lib\site-packages\win32com\server\policy.py", line
288, in _
invoke_
return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None,
None)
File "C:\Python22\Lib\site-packages\win32com\server\policy.py", line
581, in _
invokeex_
return func(*args)
File "ietest.py", line 44, in OnDocumentComplete
self.deleg.onDocumentComplete(Dispatch(disp), url)
File "ietest.py", line 122, in onDocumentComplete
self.current.onDocumentComplete(self, browser, url)
File "ietest.py", line 141, in onDocumentComplete
sink.nextStep()
File "ietest.py", line 96, in nextStep
self.current.onStart(self)
File "ietest.py", line 191, in onStart
False)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Python
COM Serve
r Internal Error', 'Unexpected Python Error: exceptions.AttributeError:
_Invoke_
', None, 0, -2147467259), None)
Did I miss something ?
TIA