简体   繁体   中英

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

I am working on a web application, and was attempting to run a basic test script with seleium, just to make sure my code was working

from selenium import webdriver
import time
import os

options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument("--test-type")
options.binary_location = os.getcwd()
driver = webdriver.Chrome(chrome_options=options, executable_path=r'./chromedriver')
driver.get('http://codepad.org')

I have the chromedriver in the current directory, and I think I am using the correct version of the chromedriver (75.0.3770.90). The full error I am getting is:

Traceback (most recent call last):
  File "test.py", line 9, in <module>
    driver = webdriver.Chrome(options=options, executable_path=r'./chromedriver')
  File "/Users/kylerood/Documents/summer19/makeFriends/env/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/Users/kylerood/Documents/summer19/makeFriends/env/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/Users/kylerood/Documents/summer19/makeFriends/env/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/Users/kylerood/Documents/summer19/makeFriends/env/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/Users/kylerood/Documents/summer19/makeFriends/env/lib/python3.7/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.

If anyone has any insight into a fix I could try that would be greatly appreciated!

Remove/comment the below line.

options.binary_location = os.getcwd()

As the binary is not located in the current working directory you are getting this error message.

binary_location is the location where your chrome.exe is located.

And make sure you have the chromedriver in the same folder you have this test located. Otherwise your script will fail with below error message.

selenium.common.exceptions.WebDriverException: Message: 'chromedriver` executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

The value binary_location must be an .exe file which specify the chrome.exe you want to run.

So this code works for me:

chrome_options = Options()
chrome_options.binary_location = '****\\chrome.exe'
driver = webdriver.Chrome(executable_path=os.path.abspath("chromedriver\\chromedriver.exe"),   options=chrome_options)

Hope it helps you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create a Chrome process error with ChromeDriver Chrome Selenium selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create Chrome process with ChromeDriver Chrome with Selenium Python selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start with Selenium and Chrome on RaspberryPi Selenium.common.exceptions.WebDriverException: Message: unknown error: no chrome binary selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally with ChromeDriver Chrome and Selenium selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed with ChromeDriver and Selenium in Python selenium.common.exceptions.WebDriverException: Message: unknown error: chrome failed to start while executing selenium python script on ubuntu TDD-Django(deploy) Error : selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally. Dockerize Flask Application Selenium gives "selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary" on Mac
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM