|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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:
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 |
|
#2
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Can't get to Internet Explorer COM object |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|