By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,213 Members | 1,092 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,213 IT Pros & Developers. It's quick & easy.

pythoncom and IDispatch

P: n/a
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
May 15 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"fraca7" <fr****@free.fr> wrote in message news:44**********************@news.free.fr...
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).
As I understand it, this was done as a security measure to foil script
exploits.
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:


You can access the underlying IDispatch using the
_oleobj_ property, ie elt.onchange._oleobj_.Invoke(......)

Alternately, you can also use FireEvent, which would look
something like this (untested):
elt.FireEvent('onchange',elt.onchange)
Roger

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
May 17 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.