【发布时间】:2017-05-24 20:05:17
【问题描述】:
我正在将 selenium 用于带有 chromedriver 的 python。不幸的是,我还没有找到一种方法来处理 chromedriver 在 python 中引发的错误!
如果我使用 selenium 打开任何网站:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
opts = Options()
prefs = {"profile.managed_default_content_settings.images": 2}
opts.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(chrome_options=opts)
driver.delete_all_cookies()
driver.get("https://www.google.de/")
#Some more actions
driver.close()
如果我(手动)关闭浏览器窗口,脚本正在运行,我会收到以下错误:
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
(Session info: chrome=55.0.2883.87)
(Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Windows NT 10.0.14393 x86_64)
如果我将上面的 python 代码完全放在 try/except 括号中,如果 chrome 刹车,则不会执行异常!相反,整个程序都会刹车!
有没有办法处理python中chromedriver引发的错误?
感谢您的建议!
编辑: 我想我的问题没有很好地表达出来。我的脚本工作正常,如果有人手动关闭浏览器窗口,我只想处理异常。现在我的整个 python 工具,包括我的 gui 崩溃了......
【问题讨论】:
标签: python selenium error-handling python-3.4 selenium-chromedriver