[英]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我正在开发一个 Web 应用程序,并试图用 seleium 运行一个基本的测试脚本,以确保我的代码正常工作
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).我在当前目录中有 chromedriver,我想我使用的是正确版本的 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.
binary_location 是 chrome.exe 所在的位置。
And make sure you have the chromedriver in the same folder you have this test located.并确保 chromedriver 位于此测试所在的同一文件夹中。 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.值
binary_location
必须是指定要运行的chrome.exe
的 .exe 文件。
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希望对你有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.