[Ironpython-users] Failing to catch exception

Kuno Meyer kuno.meyer at gmx.ch
Fri May 8 15:38:41 CEST 2015


Hi David

I cannot reproduce your issue (see below).

Since you are not able to catch the exception with a catch-all statement:

- Are you sure that the observed NoSuchElementException in the debugger
actually stems from code inside of the 'try' block?
- What does "crashing" mean? Could it be that the application crashes in
some unmanaged code portion executed in some inner 'catch' or 'final' block,
before it actually reaches your 'except' block?

Kuno

-----

import clr
import sys

sys.path.append(r"[...]")

clr.AddReference("WebDriver.dll")
from OpenQA.Selenium import *
from OpenQA.Selenium.IE import *

class MyWindow(object):
    def __init__(self):

        # Initialize the Selenium object and open the page to parse
        self.driver = InternetExplorerDriver()
        self.driver.Navigate().GoToUrl("http://www.google.com")

    def ParseStoryStandardFormat(self):
        try:
            flagIndicator = self.driver.FindElementByClassName("flag-indicator")
        except NoSuchElementException as ex:
            print ex

w = MyWindow()
w.ParseStoryStandardFormat();

-----

D:\mytemp>"c:\Program Files (x86)\IronPython 2.7\ipy.exe" selenium.py
Started InternetExplorerDriver server (32-bit)
2.41.0.0
Listening on port 49736
OpenQA.Selenium.NoSuchElementException: Unable to find element with class
name == flag-indicator
   at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response
errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String
driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism,
String value)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByClassName(String
className)
   at
Microsoft.Scripting.Interpreter.FuncCallInstruction`3.Run(InterpretedFrame
frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0
arg0, T1 arg1, T2 arg2, T3 arg3)
   at
System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite
site, T0 arg0, T1 arg1, T2 arg2)
   at
Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)



More information about the Ironpython-users mailing list