使用Selenium时是否需要安装Chrome或仅安装chromedriver? [英] Is Chrome installation needed or only chromedriver when using Selenium?

查看:683
本文介绍了使用Selenium时是否需要安装Chrome或仅安装chromedriver?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试搜索,但没有找到明确的答案.在Windows Server 2016上,没有实际安装Chrome浏览器.我下载了正确的"chromedriver.exe"并将其放置在"D:\ Apps \ chromedriver.exe"中.我已将完整路径添加为"D:\ Apps \ chromedriver.exe".

I've tried to search, but haven't found a definitive answer. On Windows Server 2016 WITHOUT Chrome Browser actually installed. I downloaded the correct "chromedriver.exe" and placed it in "D:\Apps\chromedriver.exe". I have added to my environment PATH the full path as "D:\Apps\chromedriver.exe".

当我尝试启动使用最新Selenium的Windows服务时,出现以下错误:

When I attempt to start my Windows Service that utilizes the latest Selenium, I get the following error:

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(以下为完整披露而包括在内):

Question: Do I have to actually install the full-blown browser in addition to the chromedriver, or is this simply just not finding the chromedriver.exe in my Python code (included below for full disclosure):

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)

推荐答案

用户提供了相关链接,以确认是",除了实际的chromedriver外,还需要完整的Chrome安装.

Users provided relevant link to confirm that, "YES" a full Chrome installation is needed in addition to the actual chromedriver.

链接: https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver

这篇关于使用Selenium时是否需要安装Chrome或仅安装chromedriver?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆