小编Nir*_*eya的帖子

python selenium driver.quit() 在 except 块内

我的应用程序是这样的,如果它抛出异常,我希望驱动程序关闭,我尝试了以下代码,但它抛出异常。

我的代码:其中 url 是我要打开的网址

driver=webdriver.Firefox()
try:
   driver.get(url)

except:

   driver.quit()
Run Code Online (Sandbox Code Playgroud)

它正在关闭驱动程序但抛出异常。我应该如何解决这个问题?

这是我的堆栈跟踪

raceback (most recent call last):
  File "/folderpath", line 47, in <module>
    driver.close()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 505, in close
    self.execute(Command.CLOSE)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 231, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 395, in execute
    return self._request(command_info[0], url, body=data)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 425, in _request
    self._conn.request(method, parsed_url.path, body, headers)
  File "/usr/lib/python2.7/httplib.py", line 973, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python2.7/httplib.py", line 1007, in _send_request
    self.endheaders(body)
  File "/usr/lib/python2.7/httplib.py", line …
Run Code Online (Sandbox Code Playgroud)

python exception selenium-webdriver

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

exception ×1

python ×1

selenium-webdriver ×1