Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 30th, 2004, 04:29 PM
karlovac karlovac is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 40 karlovac User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 10
Can't get to Internet Explorer COM object

Hi all

I've been working on a python script that for testing web applications. It:

1) Opens up Internet Explorer
2) Loads a URL
3) Takes a screenshot
4) Compares the screenshot with a previous one
5) Alerts people by email if there is a discrepancy
6) Quits Internet Explorer

It repeats the above process for a number of URLs.

On my development box, it worked fine. When I moved it to a much slower box, with a fresh install of Windows 2k and Python, it started breaking at random:

Quote:
Traceback (most recent call last):
File "apptester.py", line 278, in ?
t.makeGoldenFiles()
File "apptester.py", line 152, in makeGoldenFiles
self.makeGoldenFile( app )
File "apptester.py", line 97, in makeGoldenFile
ie.Visible = 1
File "C:\Python22\Lib\site-packages\win32com\client\dynamic.py", line 521, in __setattr__
raise AttributeError, "Property '%s.%s' can not be set." % (self._username_,
attr)
AttributeError: Property 'InternetExplorer.Application.Visible' can not be set.


It's breaking before it even gets to do a comparison of screenshots; at the point where it's taking the "good" screenshot.

Note that this doesn't necessarily happen at the same point in the loop. I started adding sleep() calls to give internet explorer time to fully start up, but I'm not sure if that's helping.

I suspect that this is because the new box is so much slower, but I'm not sure.

Here's the bit of code that opens the browser and saves the image:

Code:
    def makeGoldenFile( self, app ):
        global g_goldenFilesTimeout
        ie = win32com.client.Dispatch( "InternetExplorer.Application" )
        time.sleep( 2 )
        ie.Visible = 1
        ie.FullScreen = 1
        ie.Navigate( app.url )
        time.sleep( g_goldenFilesTimeout )
        # Screenshot
        fn = app.getGoldenFilename()
        cmd = "c:\\PROGRA~1\\CAP\\cap.exe /full /file=" + fn
        os.system( cmd )
        ie.Quit()
        self.addIgnoreAreas( fn, app )
        return self.compareScreenshots( fn, app.getGoldenFilename() )


I've highlighted the line Python is complaining about. I've tried increasing the sleep call to 5, but that didn't help (although it did repeat the cycle several more times before breaking).

Any ideas?

-Antun

Reply With Quote
  #2  
Old March 31st, 2004, 01:49 AM
DevCoach DevCoach is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,585 DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 2 h 58 m 23 sec
Reputation Power: 1372
I have had the same problem scripting Excel from Python, and I agree with your diagnosis that you are trying to use the COM object before IE has fully initialised.

You could try looping until it works:

Code:
while 1:
    try:
        ie.Visible = 1
        break
    except AttributeError:
        sleep(1)


Of course if you accidentally tried this on an attribute that does not exist then it would loop forever, so either test it carefully or replace the 'while 1' with a 'for x in xrange(60)' to give a large timeout.

Incidentally, does it make a difference if there is already an instance of IE running? If it has to be loaded from scratch then the startup is going to take longer. The startup time is also likely to be affected by the version of IE installed, number of plugins it has to load, etc.

Regards,

Dave - The Developers' Coach

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Can't get to Internet Explorer COM object

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap