当前位置: 首页 > 知识库问答 >
问题:

进程从chrome位置开始 /usr/bin/google-chrome不再运行,因此ChromeDriver假设Chrome已为Selenium崩溃

商振
2023-03-14

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

Ubuntu代码:

which google-chrome

输出:

/usr/bin/google-chrome

jupyter笔记本代码:

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")

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

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

共有1个答案

苗森
2023-03-14

此错误消息...

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无法启动/生成新的WebBrowser,即Chrome浏览器会话。

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

  • 您使用的是chromedriver=74.0.3729.6

支持Chrome v74

  • 也许您使用的是Chrome浏览器的最新版本,即Chrome=73。x个

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

  • 将ChromeDriver降级为ChromeDriver v73.0.3683.68级别。
  • 将Chrome版本保持在Chromev73级别。(根据ChromeDriver v73.0.3683.68发行说明)
  • 通过IDE清理您的项目工作区并仅使用所需的依赖项重建您的项目。
  • 执行您的@Test
  • 始终在tearDown(){}方法中调用driver.quit()以关闭
 类似资料:
  • 问题内容: 最近,我更换了计算机,从那时起,我无法使用selenium启动铬。我也尝试过Firefox,但浏览器实例无法启动。 我收到以下错误: 编辑:尝试@ b0sss解决方案后,我得到以下错误。 问题答案: 尝试在此处下载并使用此最新的chrome驱动程序版本。 https://sites.google.com/a/chromium.org/chromedriver/downloads 编辑:

  • 问题内容: 最近,我更换了计算机,从那时起,我无法使用selenium启动铬。我也尝试过Firefox,但浏览器实例无法启动。 我收到以下错误: 我安装了最新的Chrome版本和chromedriver 编辑:尝试@ b0sss解决方案后,我得到以下错误。 问题答案: 尝试在此处下载并使用此最新的chrome驱动程序版本。 https://sites.google.com/a/chromium.o

  • 在我开始之前:我知道有10亿篇关于硒不起作用的帖子,还有各种各样的解决方案需要尝试。我相信我什么都试过了,但如果我错过了什么,请原谅。我的头撞到墙上了,非常感谢你的帮助。 以下是我采取的一些措施: 我下载了chromedriver for selenium(Ubuntu,Python),并使用和使驱动程序可执行。之后,我用。 我尝试了各种Selenium选项,包括手动添加chromedriver运

  • 我正在尝试在AmazonLinux上设置一个jenkins服务器来托管我的自动化框架,其中包含Selenium-webDrive(3.142.0)和ruby(2.3.7)。如果我尝试使用我的脚本调用chrome驱动程序,它会说, “Selenium::WebDriver::Error::UnknownError:未知错误:Chrome无法启动:异常退出(未知错误:DevToolsActivePor

  • 首先,对于selenium,我不想使用chromium(Linux中默认使用chromium),我想使用google chrome。其次,当我用selenium下载一个文件时,我想用一个特定的路径下载该文件,例如:src/resources/downloadFiles/它不工作,默认情况下需要/home/myuser/Downloads 这是我的代码: 受保护的final static路径下载路径

  • 问题内容: 我下载了ChromeDriver,默认情况下,浏览器语言为英语,我需要将其更改为西班牙语,但我一直无法使用。 问题答案: 您可以通过添加Chrome的命令行开关 “ –lang”来实现。 基本上,所有你需要开始与ChromeOption说法,见API的详细信息。 以下是有关如何使用Selenium以西班牙语启动Chrome的C#代码的工作示例。 Java代码应该几乎相同(未经测试)。请