selenium.common.exceptions.WebDriverException:消息:未知错误:无法使用 ChromeDriver Chrome Selenium 创建 Chrome 进程错误

2024-04-26

我正在尝试编写基本的 python-Google Chrome 与 webdriver 交互的代码,但在尝试在浏览器上启动链接时不断遇到相同的错误。

这是我的代码:

from selenium import webdriver
import os

class Instagrambot:
    def __init__(self, username, password):
        self.username = username
        self.password = password

        self.driver = webdriver.Chrome('./chromedriver.exe')


if __name__ == '__main__':
    ig_bot = Instagrambot('temp_username', 'temp_password')

我的当前目录中有 chromedriver,并且我正在为我的浏览器 (Chrome 79.0.3945.88) 使用正确版本的 chromedriver (79.0.3945.36) 。我得到的完整错误是:

Traceback (most recent call last):
  File "c:/Users/Arthur/Documents/instabot/bot.py", line 16, in <module>
    ig_bot = Instagrambot('temp_username', 'temp_password')
  File "c:/Users/Arthur/Documents/instabot/bot.py", line 12, in __init__
    self.driver = webdriver.Chrome('./chromedriver.exe')
  File "C:\Users\Arthur\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__desired_capabilities=desired_capabilities)
  File "C:\Users\Arthur\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__self.start_session(capabilities, browser_profile)
  File "C:\Users\Arthur\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\Arthur\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Arthur\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response 
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create a Chrome process.

我已经尝试过:

写入 chromedriver.exe 的完整可执行路径(bot.py 的同一文件夹)

按照此答案中的建议覆盖 Chrome 二进制位置:https://stackoverflow.com/a/53078276/11206079 https://stackoverflow.com/a/53078276/11206079

如果有人可以帮助我或提供有关如何修复它的任何见解,我将非常高兴!


这个错误信息...

selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create a Chrome process.

...意味着Chrome驱动程序无法启动/产生新的浏览上下文 i.e. Chrome浏览器会议。

我在您的代码块中没有看到任何此类问题。不过,关于您的更多详细信息测试环境关于您正在使用的二进制文件的版本和用户类型将帮助我们以更好的方式调试问题。然而,最有可能的是你正在执行你的测试行政人员


经验法则

Chrome 在启动期间崩溃的一个常见原因是将 Chrome 运行为root user (administrator)在 Linux 上。虽然可以通过传递来解决这个问题--no-sandbox在创建 WebDriver 会话时标记,这样的配置不受支持并且强烈建议不要这样做。您需要将环境配置为以普通用户身份运行 Chrome。


其他注意事项

确保这件事:

  • Selenium升级到当前级别版本 3.141.59 https://docs.seleniumhq.org/download/.
  • Chrome驱动程序已更新为当前ChromeDriver v79.0.3945.36 https://chromedriver.storage.googleapis.com/index.html?path=79.0.3945.36/ level.
  • Chrome已更新为当前Chrome 版本 79.0等级。 (按照ChromeDriver v79.0 发行说明 https://chromedriver.storage.googleapis.com/79.0.3945.36/notes.txt)
  • Clean your 项目工作区通过你的IDE and Rebuild您的项目仅具有所需的依赖项。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

selenium.common.exceptions.WebDriverException:消息:未知错误:无法使用 ChromeDriver Chrome Selenium 创建 Chrome 进程错误 的相关文章

随机推荐