【问题标题】:Getting Selenium to Work with Firefox Driver on C# Latest 3.9.0让 Selenium 在 C# 最新 3.9.0 上与 Firefox 驱动程序一起工作
【发布时间】:2018-07-17 20:10:23
【问题描述】:

我无法让 Selenium 与 c# 上的 Firefox 驱动程序一起工作。 Chrome 可以完美运行,但 Firefox 不行。

使用:

  • 网络 4.6.1
  • 最新版的 selenium 3.9.0
  • Gecko-driver 下载自(管理 Nuget 包)0.19.1
  • 使用 MSTest.TestAdapater,它应该与 Chrome 一样完美地工作。

我已经在 Windows 中设置了路径变量。

GeckoDriver 已安装在源代码的 Bin 文件夹中。

Firefoxdriverservice 不存在,因此无法使用该命令。

我得到的错误是“抛出异常: System.ComponentModel.Win32Exception: 系统找不到指定的文件"

using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using System.Windows.Forms;

 namespace BeatRecaptcha
{
[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestMethod1()
    {

        IWebDriver driver = new FirefoxDriver();
        driver.Manage().Window.Maximize();

        //Go to Google
        driver.Navigate().GoToUrl("www.google.co.uk");

    }
}

}

【问题讨论】:

  • 您是否使用 NuGet 安装了所有内容?

标签: c# selenium firefox geckodriver


【解决方案1】:

不确定您是否最近升级到了最新版本的 selenium,但自 Selenium 3.0 起,您还需要根据您的系统配置从以下网址下载 geckodriver.exe。

https://github.com/mozilla/geckodriver/releases

然后你可以试试这样的:

//Give the path of the geckodriver.exe    
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(@"C:\Users\abcd\Downloads\geckodriver-v0.13.0-win64","geckodriver.exe")

//Give the path of the Firefox Browser        
service.FirefoxBinaryPath = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";

IWebDriver driver = new FirefoxDriver(service);
driver.Navigate().GoToUrl("https://www.google.com");

【讨论】:

    【解决方案2】:

    想通了,伙计们。

    事实证明,3.8.0 仅支持 C#,而不是 3.9nuget 自动安装为 WebDriver。 现在一切正常,您甚至不必指定 driverservice 并将其指向路径,因为它会自动拾取它。

    【讨论】:

      【解决方案3】:

      通过 nuget 包安装 Selenium.WebDriver.GeckoDriver。 (1) 右键项目选择管理nuget包

      安装后你的references在项目中看起来像

      在此之后您将不会收到错误

      【讨论】:

      • 为什么不在selenium账号下发布,jsakamoto是谁?
      • 有些人主动创造了这些驱动程序。 Selenium 并不为所有浏览器提供这些额外的东西。这是那个人的 github id。他只是个微软人
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-12
      • 1970-01-01
      • 1970-01-01
      • 2019-05-09
      • 2016-12-13
      相关资源
      最近更新 更多