问题描述
我正在尝试使用webdriver对python-Google Chrome的基本交互进行编码,但是在尝试在浏览器中启动链接时,我始终遇到相同的错误.
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.
这是我的代码:
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).我得到的完整错误是:
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.
我已经尝试过:
将完整的可执行文件路径写入chromedriver.exe(与bot.py相同的文件夹)
Writing the full executable path towards chromedriver.exe (same folder of bot.py)
按照此答案中的建议覆盖Chrome二进制文件的位置: https://stackoverflow.com/a/53078276/11206079
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!
推荐答案
此错误消息...
selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create a Chrome process.
...表示 ChromeDriver 无法启动/产生新的浏览上下文,即 Chrome浏览器会话.
...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session.
我在您的代码块中没有看到任何此类问题.但是,有关您的 Test Environment 的更多详细信息,以及所使用的二进制版本和用户类型,将有助于我们以更好的方式调试问题.但是,最有可能您以管理员
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
以非管理员/非root用户用户的身份执行 test .
确保:
- 硒已升级到当前级别版本3.141.59 .
- ChromeDriver 已更新为当前的 ChromeDriver v79.0.3945.36 级别.
- Chrome 已更新为当前的 Chrome版本79.0 级别. (根据 ChromeDriver v79.0发行说明) 通过 IDE
- 清理您的项目工作区和重建您的项目,并且仅具有必需的依赖项.
- 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.
这篇关于selenium.common.exceptions.WebDriverException:消息:未知错误:无法使用ChromeDriver Chrome Selenium创建Chrome进程错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!