具有无头镀铬的设置硒错误:WebDriverException:消息:未知错误:Chrome无法启动:异常退出

问题描述 投票:0回答:1

我正在尝试在以下环境中使用无头铬运行硒:作业系统:Ubuntu 16.04.6Chrome:77.0.3865.90(正式版本)(64位)ChromeDriver:77.0.3865.40硒服务器版本:3.141.59,修订版:e82be7d358

我一直在developer.google.com读过它,并关注推荐的Running Selenium with Headless Chrome帖子。我按照ipython REPL中的步骤操作:

from selenium import webdriver

options = webdriver.ChromeOptions()

options.binary_location = '/usr/local/bin'

options.add_argument('headless')

options.add_argument('window-size=1200x600')

driver = webdriver.Chrome(chrome_options=options)

但是这导致以下错误:

WebDriverException                        Traceback (most recent call last)
<ipython-input-6-658404e774ae> in <module>()
----> 1 driver = webdriver.Chrome(chrome_options=options)

/home/user/.local/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.pyc in __init__(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options, keep_alive)
     79                     remote_server_addr=self.service.service_url,
     80                     keep_alive=keep_alive),
---> 81                 desired_capabilities=desired_capabilities)
     82         except Exception:
     83             self.quit()

/home/user/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.pyc in __init__(self, command_executor, desired_capabilities, browser_profile, proxy, keep_alive, file_detector, options)
    155             warnings.warn("Please use FirefoxOptions to set browser profile",
    156                           DeprecationWarning, stacklevel=2)
--> 157         self.start_session(capabilities, browser_profile)
    158         self._switch_to = SwitchTo(self)
    159         self._mobile = Mobile(self)

/home/user/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.pyc in start_session(self, capabilities, browser_profile)
    250         parameters = {"capabilities": w3c_caps,
    251                       "desiredCapabilities": capabilities}
--> 252         response = self.execute(Command.NEW_SESSION, parameters)
    253         if 'sessionId' not in response:
    254             response = response['value']

/home/user/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.pyc in execute(self, driver_command, params)
    319         response = self.command_executor.execute(driver_command, params)
    320         if response:
--> 321             self.error_handler.check_response(response)
    322             response['value'] = self._unwrap_value(
    323                 response.get('value', None))

/home/user/.local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.pyc in check_response(self, response)
    240                 alert_text = value['alert'].get('text')
    241             raise exception_class(message, screen, stacktrace, alert_text)
--> 242         raise exception_class(message, screen, stacktrace)
    243 
    244     def _value_or_default(self, obj, key, default):

WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/local/bin is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

我一直在四处寻找this答案。我已经看到'headless'参数是这样传递的:add_argument("--headless")。我尝试将其与'--'相加,但结果相同。在this comment中也建议使用--no-sandbox参数,但是在我的情况下,添加此参数也不会改变任何内容。

我如何调试和修复此错误?

python selenium selenium-webdriver selenium-chromedriver google-chrome-headless
1个回答
0
投票

多个更改,完整路径

options.binary_location = '/usr/local/bin/chromedriver'



options.add_argument('--headless')

要设置分辨率,我将在初始化驱动程序对象之后使用它

driver.set_window_size(1280, 1024)
© www.soinside.com 2019 - 2024. All rights reserved.