I'm having problems with some attributes in Internet Explorer.
I'm trying to figure out how to set things up so I don't have to do my
own event loop even though I'm using DispatchWithEve nts()
The reason why is that I'm doing lots of "looking at the IE Document
object then poking IE" processing. Specifically I'm trying to
implement an IE "object" that you can use to write "macro" scripts to
do long and boring point'n'click routines in Oracle Portal.
One of the reasons I need to use DispatchWithEve nts() is to grab the
OnNewWindow2 event and get a reference to any new windows that get
opened either by javascript or targeted links. Otherwise I'd not use
events, which releases you from needing to pump events.
I've read "Python Programming on Win32" (and tried really hard to grok
Appendix D) and googled until they threatened to block my IP address.
example #1
import time
import pythoncom as pc
import win32com.client as wc
class EventsClass:
pass
ie=wc.DispatchW ithEvents('Inte rnetExplorer.Ap plication.1', EventsClass)
ie.Visible=1
ie.Navigate('ht tp://www.webexpressi ons.com/how-to/examples/frames/frame4.htm')
while ie.ReadyState != 4:
time.sleep(0.25 )
pc.PumpWaitingM essages()
print ie.Document.fra mes
print ie.Document.fra mes.length
for i in range(ie.Docume nt.frames.lengt h):
print ie.Document.fra mes[i].name
print ie.Document.par entWindow
while 1:
time.sleep(0.25 )
pc.PumpWaitingM essages()
OK, you run this and it prints:
[object]
3
menu
header
main
[object]
This is ok except for the event loop. So experimented with
sys.coinit_flag s, which does get rid of the need to pump events, but
then the "parentWind ow" and "frames" attributes no longer work!!!
(the "frames" collection is the IE instances (I think) for each of the
frame subwindows, each with their own Document objects, etc)
example #2
import sys
sys.coinit_flag s = 0
import time
import win32com.client as wc
class EventsClass:
pass
ie=wc.DispatchW ithEvents('Inte rnetExplorer.Ap plication.1', EventsClass)
ie.Visible=1
ie.Navigate('ht tp://www.webexpressi ons.com/how-to/examples/frames/frame4.htm')
while ie.ReadyState != 4:
time.sleep(0.25 )
print ie.Document.fra mes
print ie.Document.fra mes.length
for i in range(ie.Docume nt.frames.lengt h):
print ie.Document.fra mes[i].name
print ie.Document.par entWindow
Traceback (most recent call last):
File "C:\example2.py ", line 15, in ?
print ie.Document.fra mes
File "C:\PROGRA~1\PY THON\lib\site-packages\win32c om\client\dynam ic.py", line 4
54, in __getattr__
raise pythoncom.com_e rror, details
pywintypes.com_ error: (-2147467262, 'No such interface supported', None, None)[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
Why is this? What's going on here?
-gc
--
Windows users [are like] people stuck in abusive relationships. They
get beat up over and over again, but they won't leave.
-- Steve VanDevender (alt.sysadmin.r ecovery)
I'm trying to figure out how to set things up so I don't have to do my
own event loop even though I'm using DispatchWithEve nts()
The reason why is that I'm doing lots of "looking at the IE Document
object then poking IE" processing. Specifically I'm trying to
implement an IE "object" that you can use to write "macro" scripts to
do long and boring point'n'click routines in Oracle Portal.
One of the reasons I need to use DispatchWithEve nts() is to grab the
OnNewWindow2 event and get a reference to any new windows that get
opened either by javascript or targeted links. Otherwise I'd not use
events, which releases you from needing to pump events.
I've read "Python Programming on Win32" (and tried really hard to grok
Appendix D) and googled until they threatened to block my IP address.
example #1
import time
import pythoncom as pc
import win32com.client as wc
class EventsClass:
pass
ie=wc.DispatchW ithEvents('Inte rnetExplorer.Ap plication.1', EventsClass)
ie.Visible=1
ie.Navigate('ht tp://www.webexpressi ons.com/how-to/examples/frames/frame4.htm')
while ie.ReadyState != 4:
time.sleep(0.25 )
pc.PumpWaitingM essages()
print ie.Document.fra mes
print ie.Document.fra mes.length
for i in range(ie.Docume nt.frames.lengt h):
print ie.Document.fra mes[i].name
print ie.Document.par entWindow
while 1:
time.sleep(0.25 )
pc.PumpWaitingM essages()
OK, you run this and it prints:
[object]
3
menu
header
main
[object]
This is ok except for the event loop. So experimented with
sys.coinit_flag s, which does get rid of the need to pump events, but
then the "parentWind ow" and "frames" attributes no longer work!!!
(the "frames" collection is the IE instances (I think) for each of the
frame subwindows, each with their own Document objects, etc)
example #2
import sys
sys.coinit_flag s = 0
import time
import win32com.client as wc
class EventsClass:
pass
ie=wc.DispatchW ithEvents('Inte rnetExplorer.Ap plication.1', EventsClass)
ie.Visible=1
ie.Navigate('ht tp://www.webexpressi ons.com/how-to/examples/frames/frame4.htm')
while ie.ReadyState != 4:
time.sleep(0.25 )
print ie.Document.fra mes
print ie.Document.fra mes.length
for i in range(ie.Docume nt.frames.lengt h):
print ie.Document.fra mes[i].name
print ie.Document.par entWindow
Traceback (most recent call last):
File "C:\example2.py ", line 15, in ?
print ie.Document.fra mes
File "C:\PROGRA~1\PY THON\lib\site-packages\win32c om\client\dynam ic.py", line 4
54, in __getattr__
raise pythoncom.com_e rror, details
pywintypes.com_ error: (-2147467262, 'No such interface supported', None, None)[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
Why is this? What's going on here?
-gc
--
Windows users [are like] people stuck in abusive relationships. They
get beat up over and over again, but they won't leave.
-- Steve VanDevender (alt.sysadmin.r ecovery)