我试图搜索,但没有找到明确的答案。在没有实际安装 Chrome 浏览器的 Windows Server 2016 上。我下载了正确的“chromedriver.exe”并将其放在“D:\Apps\chromedriver.exe”中。我已将完整路径添加到我的环境 PATH 中,如“D:\Apps\chromedriver.exe”。
当我尝试启动使用最新 Selenium 的 Windows 服务时,出现以下错误:
Exception occurred: Failed initializing web driver: Message: unknown error: cannot find Chrome binary
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.14393 x86_64)
问题:除了 chromedriver 之外,我是否必须实际安装功能齐全的浏览器,或者这只是在我的 Python 代码中找不到 chromedriver.exe(包含在下面以供全面披露):
def __init__(self, username, password, environment='cert'):
self.username = username
self.password = password
self.environment = environment
# Instantiate a chrome options object so you can set the size and headless preference
self.chrome_options = Options()
# Toggle Headless or not
if HEADLESS_TOGGLE == 1:
self.chrome_options.add_argument("--headless")
self.chrome_options.add_argument("--disable-gpu") # Disables "Lost UI Shared Context GPU Error on Windows"
self.chrome_options.add_argument('--disable-extensions') # Disables Extensions
self.chrome_options.add_argument("--disable-software-rasterizer") # Disables "Lost UI Shared Context GPU Error on Windows"
self.chrome_options.add_argument("--window-size=1024x768")
self.chrome_options.add_argument("--log-level=3") # Errors Only
self.chrome_options.add_argument("--incognito") # Keeps history and logs clear
self.chrome_options.add_argument("--no-sandbox")
self.chrome_options.add_argument("--mute_audio") # No loud surprises!
self.chrome_options.add_argument("--no-gpu") # Disables gpu-based errors (headless)
self.driver = webdriver.Chrome(chrome_options=self.chrome_options)
原文由 Source Matters 发布,翻译遵循 CC BY-SA 4.0 许可协议
用户提供了相关链接以确认“是”除了实际的 chromedriver 之外还需要完整的 Chrome 安装。
链接: https ://github.com/SeleniumHQ/selenium/wiki/ChromeDriver