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

huangapple go评论88阅读模式
英文:

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

问题

以下是您提供的Python代码的翻译:

我正在尝试使用webdriver编写基本的Python-Google Chrome交互但在尝试启动浏览器上的链接时我不断收到相同的错误

这是我的代码

    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在当前目录中并且我正在使用正确版本的chromedriver79.0.3945.36适用于我的浏览器Chrome 79.0.3945.88)。我收到的完整错误如下

    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

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

请注意,翻译中保留了代码和错误消息的原始格式。如果您需要更多帮助或有其他问题,请随时提问。

英文:

I am trying to code basic python-Google Chrome interactions with webdriver but I constantly get the same error while trying to launch a link on my browser.

Here is my code:

from selenium import webdriver
import os
class Instagrambot:
def __init__(self, username, password):
self.username = username
self.password = password
self.driver = webdriver.Chrome(&#39;./chromedriver.exe&#39;)
if __name__ == &#39;__main__&#39;:
ig_bot = Instagrambot(&#39;temp_username&#39;, &#39;temp_password&#39;)

I have the chromedriver in the current directory, and I am using the correct version of the chromedriver (79.0.3945.36) for my browser (Chrome 79.0.3945.88) . The full error I am getting is:

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

I have already tried:

Writing the full executable path towards chromedriver.exe (same folder of bot.py)

Overriding the Chrome binary location as suggested in this answer:
https://stackoverflow.com/a/53078276/11206079

If anyone can help me or give any insight about how to fix it I would be really glad!

答案1

得分: 2

selenium.common.exceptions.WebDriverException: 消息:未知错误:无法创建Chrome进程。

这意味着ChromeDriver无法初始化/启动新的浏览上下文,即Chrome浏览器会话。

我在您的代码块中没有看到此类问题。然而,有关您的_测试环境_的更多详细信息,包括您使用的二进制文件版本和用户类型,将有助于我们更好地调试此问题。但最可能的情况是您以管理员身份执行您的测试。

Thumb rule

常见导致Chrome在启动期间崩溃的原因是在Linux上以**root用户(管理员**)身份运行Chrome。虽然可以通过在创建WebDriver会话时传递--no-sandbox标志来解决此问题,但这种配置不受支持且不建议使用。您需要配置环境以普通用户身份运行Chrome。

其他考虑事项

确保:

英文:

This error message...

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

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

I don't see any such issue in your code block. However, a bit more details about your Test Environment with respect to version of the binaries and user type you are using would have helped us to debug the issue in a better way. However most possibly you are executing your test as an administrator


<i>Thumb rule</i>

><i>A common cause for Chrome to crash during startup is running Chrome as root user (administrator) on Linux. While it is possible to work around this issue by passing --no-sandbox flag when creating your WebDriver session, such a configuration is unsupported and highly discouraged. You need to configure your environment to run Chrome as a regular user instead.</i>


Additional considerations

Ensure that:

huangapple
  • 本文由 发表于 2020年1月6日 22:56:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/59614264.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定