Python:在哪里可以找到异常导入

2024-09-29 19:33:18 发布

您现在位置:Python中文网/ 问答频道 /正文

如何找到自定义异常的定义位置,以便导入它。在代码中抛出的一个错误的stacktrace中,我得到了一个NoSuchElementException。我想捕获这个特定的异常,但我找不到从何处导入它。有没有办法确定从stacktrace导入什么?你知道吗

Traceback (most recent call last):
  File "/home/ubuntu/webapps/tablecloth/src/tablecloth/apps/atsa/adaptor.py", line 266, in login
    welcome_field = driver.find_element_by_class_name(self.welcome_id)
  File "/home/ubuntu/webapps/tablecloth/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 342, in find_element_by_class_name
    return self.find_element(by=By.CLASS_NAME, value=name)
  File "/home/ubuntu/webapps/tablecloth/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 680, in find_element
    {'using': by, 'value': value})['value']
  File "/home/ubuntu/webapps/tablecloth/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 165, in execute
    self.error_handler.check_response(response)
  File "/home/ubuntu/webapps/tablecloth/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 158, in check_response
    raise exception_class(message, screen, stacktrace)
NoSuchElementException: Message: u'Unable to locate element: {"method":"class name","selector":"userName"}' ; Stacktrace:
    at FirefoxDriver.prototype.findElementInternal_ 

Tags: nameinpyhomebyubuntulibline
1条回答
网友
1楼 · 发布于 2024-09-29 19:33:18

使用Exception捕获异常,以便您可以访问异常对象:

try:
    call_your_function()
except Exception as e:
    print e.__module__

然后将Exception替换为您找到的更具体的一个。你知道吗

相关问题 更多 >

    热门问题