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
clr.AddReference("Selenium.WebDriverBackedSelenium.dll")
clr.AddReference("ThoughtWorks.Selenium.Core.dll")
clr.AddReference("WebDriver.dll")
clr.AddReference("WebDriver.Support.dll")

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()
        self.driver.Navigate().GoToUrl("http://www.parsethispage.com";)
    [...]
    def ParseStoryStandardFormat(self):
        parsed_ok = 1
        try:
            flagIndicator =
self.driver.FindElementByClassName("flag-indicator")
            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 2.7.2.1 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.

Thanks,
David


_______________________________________________
Ironpython-users mailing list
Ironpython-users@python.org
https://mail.python.org/mailman/listinfo/ironpython-users

Reply via email to