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

Help me. How to open a new IE window?

P: n/a
Hi

I want python(win32com) to open a new IE window.
Source is:
/******/
import win32com.client
msie = win32com.client.Dispatch("InternetExplorer.Applica tion")
msie.Visible = 1
msie.Naviagte(http://www.python.org)
/******/
The problem is the program always grabs a existed IExplorer window or
Explorer window. It never opens a new window.

Please help me. Thanx
Victor


Jul 18 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
angel wrote:
I want python(win32com) to open a new IE window.
Source is:
/******/
import win32com.client
msie = win32com.client.Dispatch("InternetExplorer.Applica tion")
msie.Visible = 1
msie.Naviagte(http://www.python.org)
/******/
The problem is the program always grabs a existed IExplorer window or
Explorer window. It never opens a new window.


I ran into that same problem. Try this:

msie = win32com.client.DispatchEx('InternetExplorer.Appli cation.1')

It seems to work for me.

-Dave

Jul 18 '05 #2

P: n/a

"angel" <da*******@yahoo.com> wrote in message
news:c7***********@news.f.de.plusline.net...
Hi

I want python(win32com) to open a new IE window.
Source is:
/******/
import win32com.client
msie = win32com.client.Dispatch("InternetExplorer.Applica tion")
msie.Visible = 1
msie.Naviagte(http://www.python.org)
/******/
The problem is the program always grabs a existed IExplorer window or
Explorer window. It never opens a new window.

Please help me. Thanx
Victor

Hi. Perhaps you may want to check out the webbrowser module:
import webbrowser as browser
browser.open("www.python.org", new=True)
OR
browser.open_new(url)

OR
IE = browser.WindowsDefault()
IE.open_new(url)

HTH,
Sean
Jul 18 '05 #3

P: n/a
It's work. Thanx again!
angel

"Dave Brueck" <da**@pythonapocrypha.com>
??????:ma**************************************@py thon.org...
angel wrote:
I want python(win32com) to open a new IE window.
Source is:
/******/
import win32com.client
msie = win32com.client.Dispatch("InternetExplorer.Applica tion")
msie.Visible = 1
msie.Naviagte(http://www.python.org)
/******/
The problem is the program always grabs a existed IExplorer window or
Explorer window. It never opens a new window.


I ran into that same problem. Try this:

msie = win32com.client.DispatchEx('InternetExplorer.Appli cation.1')

It seems to work for me.

-Dave

Jul 18 '05 #4

P: n/a
angel wrote:
Hi

I want python(win32com) to open a new IE window.
Source is:
/******/
import win32com.client
msie = win32com.client.Dispatch("InternetExplorer.Applica tion")
msie.Visible = 1
msie.Naviagte(http://www.python.org)
/******/
The problem is the program always grabs a existed IExplorer window or
Explorer window. It never opens a new window.

Please help me. Thanx
Victor


import webbrowser
webbrowser.open_new("www.python.org")

it will work fine with IE (if IE is the default browser)
Jul 18 '05 #5

P: n/a
Vladimir wrote:
angel wrote:
I want python(win32com) to open a new IE window.
Source is:
/******/
import win32com.client
msie = win32com.client.Dispatch("InternetExplorer.Applica tion")
msie.Visible = 1
msie.Naviagte(http://www.python.org)
/******/
The problem is the program always grabs a existed IExplorer window or
Explorer window. It never opens a new window.


import webbrowser
webbrowser.open_new("www.python.org")

it will work fine with IE (if IE is the default browser)


I guess the OP didn't specify, but the above won't work if you need to control
the browser from then on (which is what I assume he was trying to do by
obtaining an IDispatch pointer to it).

-Dave
Jul 18 '05 #6

P: n/a
"Dave Brueck" <da**@pythonapocrypha.com> wrote in message news:<ma**************************************@pyt hon.org>...
Vladimir wrote:
angel wrote:
I want python(win32com) to open a new IE window.
Source is:
/******/
import win32com.client
msie = win32com.client.Dispatch("InternetExplorer.Applica tion")
msie.Visible = 1
msie.Naviagte(http://www.python.org)
/******/
The problem is the program always grabs a existed IExplorer window or
Explorer window. It never opens a new window.


import webbrowser
webbrowser.open_new("www.python.org")

it will work fine with IE (if IE is the default browser)


I guess the OP didn't specify, but the above won't work if you need to control
the browser from then on (which is what I assume he was trying to do by
obtaining an IDispatch pointer to it).

-Dave


Here is how you do it:

Here is a quick way to do it but it works!
If you want to learn more go to pamie.sourceforge.net
This has a class file that helps you automate I.E.

# DispatchEX allows you to open a new window

from win32com.client import DispatchEx

import time

def wait(ie): # very important!!! you have to wait for each page to load
"Given an IE object, wait until the object is ready for input."
while ie.Busy: time.sleep(0.1)

doc = ie.Document
while doc.ReadyState != 'complete': time.sleep(0.1)
return doc

def ClickLink(ie, mylink):
#hrefs = []
for link in ie.Document.links:
if link is None: break # needed for browser bug

if link.innerText == mylink:
link.Click()
# Here is what you need
ie = DispatchEx('InternetExplorer.Application')
ie.Visible = 1
ie.Navigate ('www.python.org')

# Some extra
wait(ie)# Very Important!
ClickLink(ie,'Search')
#later
#RLM
Jul 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.