gpt4 book ai didi

c# - 为什么 Firefox 需要 GeckoDriver?

转载 作者:行者123 更新时间:2023-11-30 19:23:55 24 4
gpt4 key购买 nike

我今天有一个简单的问题:

我用这段代码创建了一个新的 selenium 项目:

FirefoxDriver driver = new FirefoxDriver();
//ChromeDriver driver = new ChromeDriver();
//InternetExplorerDriver driver = new InternetExplorerDriver();

Chrome 和 IE 开箱即用,但 Firefox 抛出:

The geckodriver.exe file does not exist in the current directory or in a directory on the PATH environment variable. The driver can be downloaded at https://github.com/mozilla/geckodriver/releases.

为什么我们必须只为 Firefox 下载/配置此驱动程序?

最佳答案

一一解答您的问题:

  1. 为什么 Firefox 需要 GeckoDriver? - 对于 47.x 版之前的 Mozila Firefox,它是旧版浏览器,我们不需要 gecko 驱动程序。 Mozila Firefox 从版本 47.x 开始,它带有 Marionette,它是 Mozilla 的 Gecko 引擎的自动化驱动程序。它可以远程控制 Gecko 平台(例如 Firefox)的 UI 或内部 JavaScript。

  2. Chrome 和 IE 开箱即用 - 理想情况下,Chrome 和 IE 都不应该工作。但是,当您在安装/配置 Google Chrome 和 MS Internet Explorer 或其他相关软件时有意/无意地将二进制文件的位置添加到环境变量中,这些二进制文件很容易自动定位和使用。

  3. 为什么我们必须只为 Firefox 下载/配置此驱动程序? - 不仅是 Firefox,Google Chrome 和 MS Internet Explorer 也可以与 Selenium 3.4.0 一起使用,您需要从 this location 强制下载 gecko 驱动程序 v0.16.0(或更高版本)或 Chrome 驱动程序或 IEDriverServer 并将其保存在您的机器中。将您的 Mozila Firefox 或 Google Chrome 或 MS Internet Explorer 升级到最新的稳定版本。在代码中使用 geckodriver/chromedriver/iedriver 的绝对路径,同时 System.setProperty 如下:

    System.setProperty("webdriver.gecko.driver",  "C:\\Utility\\BrowserDrivers\\geckodriver.exe");

关于c# - 为什么 Firefox 需要 GeckoDriver?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43660195/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com