英文:
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在当前目录中,并且我正在使用正确版本的chromedriver(79.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('./chromedriver.exe')
if __name__ == '__main__':
ig_bot = Instagrambot('temp_username', 'temp_password')
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 "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.
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。
其他考虑事项
确保:
- _Selenium_已升级到当前版本Version 3.141.59。
- _ChromeDriver_已更新到当前版本ChromeDriver v79.0.3945.36。
- _Chrome_已更新到当前的_Chrome版本79.0_级别。(根据ChromeDriver v79.0发布说明)
- 通过您的_IDE_清理您的_项目工作区_并仅重建具有所需依赖项的项目。
英文:
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:
- Selenium is upgraded to current levels Version 3.141.59.
- ChromeDriver is updated to current ChromeDriver v79.0.3945.36 level.
- Chrome is updated to current Chrome Version 79.0 level. (as per ChromeDriver v79.0 release notes)
- Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论