Hello. I got a little problem while using pythoncom to automate IE; for
some reason, changing the 'selectedIndex' on an instance of
IHTMLSelectElem ent 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.WrapO bject(elt.oncha nge)
idisp.Invoke(py thoncom.DISPID_ VALUE,
0x400, # LOCALE_USER_DEF AULT
pythoncom.DISPA TCH_METHOD,
False)
fails with an AttributeError:
Traceback (most recent call last):
File "C:\Python22\Li b\site-packages\win32c om\server\polic y.py", line
283, in _
Invoke_
return self._invoke_(d ispid, lcid, wFlags, args)
File "C:\Python22\Li b\site-packages\win32c om\server\polic y.py", line
288, in _
invoke_
return S_OK, -1, self._invokeex_ (dispid, lcid, wFlags, args, None,
None)
File "C:\Python22\Li b\site-packages\win32c om\server\polic y.py", line
581, in _
invokeex_
return func(*args)
File "ietest.py" , line 44, in OnDocumentCompl ete
self.deleg.onDo cumentComplete( Dispatch(disp), url)
File "ietest.py" , line 122, in onDocumentCompl ete
self.current.on DocumentComplet e(self, browser, url)
File "ietest.py" , line 141, in onDocumentCompl ete
sink.nextStep()
File "ietest.py" , line 96, in nextStep
self.current.on Start(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.Attr ibuteError:
_Invoke_
', None, 0, -2147467259), None)
Did I miss something ?
TIA
some reason, changing the 'selectedIndex' on an instance of
IHTMLSelectElem ent 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.WrapO bject(elt.oncha nge)
idisp.Invoke(py thoncom.DISPID_ VALUE,
0x400, # LOCALE_USER_DEF AULT
pythoncom.DISPA TCH_METHOD,
False)
fails with an AttributeError:
Traceback (most recent call last):
File "C:\Python22\Li b\site-packages\win32c om\server\polic y.py", line
283, in _
Invoke_
return self._invoke_(d ispid, lcid, wFlags, args)
File "C:\Python22\Li b\site-packages\win32c om\server\polic y.py", line
288, in _
invoke_
return S_OK, -1, self._invokeex_ (dispid, lcid, wFlags, args, None,
None)
File "C:\Python22\Li b\site-packages\win32c om\server\polic y.py", line
581, in _
invokeex_
return func(*args)
File "ietest.py" , line 44, in OnDocumentCompl ete
self.deleg.onDo cumentComplete( Dispatch(disp), url)
File "ietest.py" , line 122, in onDocumentCompl ete
self.current.on DocumentComplet e(self, browser, url)
File "ietest.py" , line 141, in onDocumentCompl ete
sink.nextStep()
File "ietest.py" , line 96, in nextStep
self.current.on Start(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.Attr ibuteError:
_Invoke_
', None, 0, -2147467259), None)
Did I miss something ?
TIA
Comment