首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从chrome位置/usr/bin/google-chrome启动的进程不再运行,因此ChromeDriver假定Chrome已经因为Selenium而崩溃

从chrome位置/usr/bin/google-chrome启动的进程不再运行,因此ChromeDriver假定Chrome已经因为Selenium而崩溃
EN

Stack Overflow用户
提问于 2019-04-11 11:40:34
回答 1查看 12.9K关注 0票数 3

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

Ubuntu代码:

代码语言:javascript
运行
复制
which google-chrome

输出:

代码语言:javascript
运行
复制
/usr/bin/google-chrome

jupyter notebook代码:

代码语言:javascript
运行
复制
driver = webdriver.Chrome(executable_path=os.path.abspath("/home/username/chromedriver"), chrome_options=chrome_options)

错误:

代码语言:javascript
运行
复制
---------------------------------------------------------------------------
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

代码:

代码语言:javascript
运行
复制
google-chrome --version

输出:

代码语言:javascript
运行
复制
Google Chrome 73.0.3683.103

错误:

代码语言:javascript
运行
复制
---------------------------------------------------------------------------
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)

更新:

代码语言:javascript
运行
复制
chrome_options.add_argument("no-sandbox")
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--headless")

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

unknown error: DevToolsActivePort file doesn't exist error while executing Selenium UI test cases on ubuntu

EN

回答 1

Stack Overflow用户

发布于 2019-04-11 14:21:05

此错误消息...

代码语言:javascript
运行
复制
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)

...implies表示ChromeDriver无法启动/衍生新的WebBrowser,即Chrome Browser会话。

您的主要问题是您正在使用的二进制文件版本之间的incompatibility,如下所示:

  • 您正在使用chromedriver=74.0.3729.6
  • 发行说明中明确提到了以下内容:

支持Chrome v74

您可能正在使用Chrome浏览器的最新GAed版本,即

因此,ChromeDriver v74.0.3729.6和Chrome浏览器v73.x之间存在明显的不匹配

解决方案

  • 将ChromeDriver降级到ChromeDriver v73.0.3683.68级别。
  • 将Chrome版本保持在Chrome v73级别。在集成开发环境中调用项目工作区,并使用所需的依赖项在@Test.
  • Always中重新生成项目。在tearDown(){}方法中调用driver.quit()以正常关闭和销毁WebDriver和Web客户端实例。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55624355

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档