我正在开发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')
我在当前目录中有chromedriver,我认为我使用的是chromedriver的正确版本(75.0.3770.90)。我得到的完整错误是:
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.
如果有人对修复程序有任何了解,我可以尝试一下,将不胜感激!
答案 0 :(得分:1)
值binary_location
必须是一个.exe文件,该文件指定要运行的chrome.exe
。
所以这段代码对我有用:
chrome_options = Options()
chrome_options.binary_location = '****\\chrome.exe'
driver = webdriver.Chrome(executable_path=os.path.abspath("chromedriver\\chromedriver.exe"), options=chrome_options)
希望它对您有帮助
答案 1 :(得分:0)
删除/注释以下行。
options.binary_location = os.getcwd()
由于二进制文件不在当前工作目录中,因此您会收到此错误消息。
binary_location是您的chrome.exe所在的位置。
并确保将chromedriver安装在该测试所在的文件夹中。否则,您的脚本将失败,并显示以下错误消息。
selenium.common.exceptions.WebDriverException: Message: 'chromedriver` executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home