问题
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:
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
Solution
Execute your test as a non-administrator / non-root user.
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.
来源:https://stackoverflow.com/questions/59614264/selenium-common-exceptions-webdriverexception-message-unknown-error-failed-to