c# - 让 Selenium 在 C# Latest 3.9.0 上与 Firefox 驱动程序一起工作

标签 c# selenium firefox geckodriver

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

使用:

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

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

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

Firefoxdriver 服务不存在,因此无法使用该命令。

我得到的错误是“抛出异常: 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");

    }
}

最佳答案

不确定您最近是否升级到最新版本的 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");

关于c# - 让 Selenium 在 C# Latest 3.9.0 上与 Firefox 驱动程序一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48665454/

相关文章:

c# - 如何在 WinForms 中绑定(bind)多对多关系?

java - Selenium 如何获取 WebElement 中的所有元素

html - 火狐: "TypeError: localStorage is null"

javascript - Firefox 渲染 OpenType 字体与字体规范不匹配

javascript - Firefox 扩展中的 IP 地址查找

c# - 如何从 .NET 在记事本中打开文本?

C# 如何从 VS2008 代码指标中排除生成的代码?

c# - 将带有id的api中的OData实体保存到 Entity Framework 中的数据库

javascript - 在 Webdriver.io v4 中使用 scroll()

python - 如何使用许多 OR 替代项来缩短长 XPath 表达式?