[Ironpython-users] Failing to catch exception

egroups at sowray.com egroups at sowray.com
Wed May 6 15:43:13 CEST 2015

I'm probably doing something extremely stupid. I'm using Selenium to parse
a web page, but can't catch the exceptions it throws:

# Add Selenium

from OpenQA.Selenium import *
from OpenQA.Selenium.IE import *
class MyWindow(Window):
    def __init__(self):
        # Initialize the Selenium object and open the page to parse
        self.driver = InternetExplorerDriver()
    def ParseStoryStandardFormat(self):
        parsed_ok = 1
            flagIndicator =
            fiUuid = syndicationIndicator.GetAttribute("data-uuid")
        except NoSuchElementException:
            parsed_ok = 0

(The [...] in the code represents where I've edited out the irrelevant
bits.) I'm using IronPython on .NET 4.0.30319 from VS 2010 with
the latest PTVS.

If there's no flag-indicator class on the web page, the code stops at the
first line of the try: and throws a NoSuchElementException. I've tried
explicitly importing the exception (from OpenQA.Selenium import
NoSuchElementException) and tried a catch-all "except:", but nothing seems
to catch this error.

If I run it from VS with debugging, it tells me the NoSuchElementException
was unhandled by user code. If I run it without debugging, the application
just crashes and terminates. To check other errors are handled, I added a
try: xyz = 123 / 0 except: xyz = 0 at the beginning of the function and
that was handled without any problem.

If anybody can shed some light on what I'm doing wrong, I'd be very grateful.


More information about the Ironpython-users mailing list