从 chrome 位置/usr/bin/google-chrome 开始的进程不再运行,因此 ChromeDriver 假设 Chrome 已为 Selenium 崩溃 [英] The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed for Selenium

查看:63
本文介绍了从 chrome 位置/usr/bin/google-chrome 开始的进程不再运行,因此 ChromeDriver 假设 Chrome 已为 Selenium 崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 ubuntu 服务器上运行一个 jupyter notebook.我正在尝试使用 chromedriver 运行下面的 selenium 代码.我收到下面的错误,但如果我在 Ubuntu 终端中运行下面的代码行,它会返回下面的输出.有谁知道问题可能是什么?我对 ubuntu 还是很陌生.

I’m running a jupyter notebook on ubuntu server. I’m trying run the selenium code below using chromedriver. I’m getting the error below but if I run the line of code below in Ubuntu terminal it returns the output below. Does anyone know what the issue might be? I’m still pretty new to ubuntu.

Ubuntu 代码:

which google-chrome

输出:

/usr/bin/google-chrome

jupyter 笔记本代码:

jupyter notebook code:

driver = webdriver.Chrome(executable_path=os.path.abspath("/home/username/chromedriver"), chrome_options=chrome_options)

错误:

---------------------------------------------------------------------------
WebDriverException                        Traceback (most recent call last)
<ipython-input-5-bcd3289fe282> in <module>
     16 options.add_argument('headless') #downlod Chrome driver.exe
     17 #driver = webdriver.Chrome(executable_path=os.path.abspath("/home/username/stuff/JobHuntCode/chromedriver"), chrome_options=chrome_options)
---> 18 driver = webdriver.Chrome(executable_path=os.path.abspath("/home/username/chromedriver"), chrome_options=chrome_options)
     19 
     20 

~/anaconda3/envs/py36/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py 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()

~/anaconda3/envs/py36/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py 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)

~/anaconda3/envs/py36/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py 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']

~/anaconda3/envs/py36/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py 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))

~/anaconda3/envs/py36/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py 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/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Linux 4.15.0-46-generic x86_64)

更新:

更新:

Ubuntu

代码:

google-chrome --version

输出:

Google Chrome 73.0.3683.103

错误:

---------------------------------------------------------------------------
WebDriverException                        Traceback (most recent call last)
<ipython-input-1-4c82dc01ab87> in <module>
     18 options.add_argument('headless') #downlod Chrome driver.exe
     19 #driver = webdriver.Chrome(executable_path=os.path.abspath("/home/username/stuff/JobHuntCode/chromedriver"), chrome_options=chrome_options)
---> 20 driver = webdriver.Chrome(executable_path=os.path.abspath("/home/username/chromedriver"), chrome_options=chrome_options)
     21 
     22 

~/anaconda3/envs/py36/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py 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()

~/anaconda3/envs/py36/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py 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)

~/anaconda3/envs/py36/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py 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']

~/anaconda3/envs/py36/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py 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))

~/anaconda3/envs/py36/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py 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/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72),platform=Linux 4.15.0-46-generic x86_64)

更新:

chrome_options.add_argument("no-sandbox")
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--headless")

出于某种原因,将上面的行添加到我的代码中解决了这个问题.我在下面的帖子中找到了代码.

For some reason adding the lines above to my code solved the issue. I found the code in the post below.

未知错误:DevToolsActivePort 文件不存在在 ubuntu 上执行 Selenium UI 测试用例时出错

推荐答案

这个错误信息...

WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Linux 4.15.0-46-generic x86_64)

...暗示 ChromeDriver 无法启动/生成新的 WebBrowserChrome 浏览器 会话.

...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.

您的主要问题是您使用的二进制文件版本之间的不兼容性,如下所示:

Your main issue is the incompatibility between the version of the binaries you are using as follows:

支持 Chrome v74

  • 也许您使用的是最新的 GAed 版本的 Chrome 浏览器,即 chrome=73.x
  • 所以 ChromeDriver v74.0.3729.6Chrome 浏览器 v73.x

    • ChromeDriver 降级到 ChromeDriver v73.0.3683.68 级.
    • Chrome 版本保持在 Chrome v73 级别.(根据 ChromeDriver v73.0.3683.68 发行说明)李>
    • 清理你的项目工作区通过你的IDE重建你的项目只需要依赖.
    • 执行你的 @Test.
    • 总是在 tearDown(){} 方法中调用 driver.quit() 来关闭 &优雅地销毁 WebDriverWeb Client 实例.
    • Downgrade ChromeDriver to ChromeDriver v73.0.3683.68 level.
    • Keep Chrome version at Chrome v73 level. (as per ChromeDriver v73.0.3683.68 release notes)
    • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
    • Execute your @Test.
    • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.

    这篇关于从 chrome 位置/usr/bin/google-chrome 开始的进程不再运行,因此 ChromeDriver 假设 Chrome 已为 Selenium 崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆