【发布时间】:2018-04-08 04:55:40
【问题描述】:
我正在尝试使用 selenium 和 Python 2.7.x 通过 Google Chrome 运行测试。这样做时,我收到以下错误:
WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 1
此错误消息的完整回溯如下所示:
Traceback (most recent call last):
File "/home/google_search/search.py", line 347, in parse_search_results
browser_type=web_browser)
File "/home/google_search/search.py", line 218, in get_urls
browser = config_browser(proxy=proxy, agent=user_agent)
File "/home/google_search/search.py", line 154, in config_browser
chrome_options=options, service_args=["--verbose"], service_log_path=CHROME_FILE_LOG
File "/home/.local/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 62, in __init__
self.service.start()
File "/home/.local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 96, in start
self.assert_process_still_running()
File "/home/.local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 109, in assert_process_still_running
% (self.path, return_code)
WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 1
我的驱动版本:ChromeDriver 2.33.506092 (733a02544d189eeb751fe0d7ddca79a0ee28cce4
我的浏览器版本:Google Chrome 62.0.3202.62
我的硒版:selenium (3.5.0)
这是如何运行的:
def config_browser(user_agent=None, proxy=None)
options = webdriver.ChromeOptions()
if user_agent is not None:
options.add_argument("--user-agent={}".format(user_agent))
if proxy is not None:
options.add_argument("--proxy-server={}".format(proxy))
profile = webdriver.Chrome(
chrome_options=options, service_args=["--verbose"], service_log_path=CHROME_FILE_LOG
)
return profile
当我运行它时,我无法获取日志,因为它在任何事情发生之前就退出了。 chromedriver 可以在我的路径(使用 chmod a+x /usr/bin/chromedriver)中的以下位置执行:/usr/bin/chromedriver。
我做了一些研究,我目前的chromedriver版本支持60-62,可能是我的版本在62以上,但这似乎不合逻辑。这里有什么问题,我该如何解决这个问题?
值得一提的是,我正在使用 pyvirtualdisplay 隐藏浏览器,它是在调用配置浏览器本身的函数之前启动的:
browser_display = Display(visible=0, size=(800, 600))
browser_display.start()
browser = config_browser(proxy=proxy, agent=user_agent)
编辑:
正如 cmets 中提到的,我尝试将我的 selenium 版本更新为 3.6.0 它仍然会产生相同的错误。所以我卸载了google-chrome-stable 并使用了预装的chromium-browser 版本:Chromium 61.0.3163.100 Built on Ubuntu , running on Ubuntu 17.04。我仍然收到与新指南完全相同的错误:
指南:
Chromium 浏览器:Chromium 61.0.3163.100 Built on Ubuntu , running on Ubuntu 17.04
硒版:3.6.0
WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 1
【问题讨论】:
-
你的 selenium 版本是什么?
-
@DurdenP 查看最新编辑,selenium 是
3.5.0 -
将 Selenium 更新到 3.6 并重试。 或者,降级 Chrome 并重试。
-
@SiKing 你如何降级 Chrome?
apt-get没有固定版吗? -
ubuntuupdates.org/pm/google-chrome-stable 但是,更新 Selenium 以匹配您的浏览器版本通常是更理想的选择。
标签: python python-2.7 google-chrome selenium