javascript execution from Python script

brueckd at tbye.com brueckd at tbye.com
Wed Aug 28 00:55:56 CEST 2002


On Tue, 27 Aug 2002, Matt Gerrans wrote:

> That works well -- you might also want to throw in an "ie.visible=1" so you
> can see (and dismiss) it.

Ah, yes, thanks for noticing that. So I went and dug up some code and 
noticed one other thing that is useful during testing and that's a way to 
bring the window to the foreground (because for me it usually opens up 
behind other windows). There's probably a good and proper way to do this, 
but this horrible hack works too:

ie.Navigate('about:blank')
while ie.Busy, etc... # wait for doc to load 
ie.Visible = 1
hwnd = win32gui.FindWindow(None, 'about:blank - Microsoft Internet 
Explorer')
if hwnd:
  win32gui.SetForegroundWindow(hwnd)

> By the way (this should probably be a different thread), is this some
> idiosycracy of my configuration:

No, more an idiosyncrasy of my code-from-memory. ;-)

> >>> import win32com
> >>> ie = win32com.client.DispatchEx('InternetExplorer.Application.1')
> Traceback (most recent call last):
>   File "<pyshell#1>", line 1, in ?
>     ie = win32com.client.DispatchEx('InternetExplorer.Application.1')
> AttributeError: 'module' object has no attribute 'client'
> >>> import win32com.client
> >>> ie = win32com.client.DispatchEx('InternetExplorer.Application.1')
> 
> Why is it necessary to import win32com.client explicitly in this case?

win32com is just a package, so importing it binds the win32com variable to 
stuff in that package's __init__.py (e.g. in this case that includes the 
SetupEnvironment function). client is also a package, and inside its 
__init__.py is DispatchEx.

-Dave





More information about the Python-list mailing list