在C#最新3.9.0上使Selenium与Firefox驱动程序一起使用

top*_*tts 1 c# firefox selenium geckodriver

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

使用方法:

  • 网络框架4.6.1
  • 硒的最新版本3.9.0
  • 壁虎驱动程序(从管理Nuget软件包)下载0.19.1
  • 使用MSTest.TestAdapater,它应该与Chrome一样完美运行。

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

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");

    }
}
Run Code Online (Sandbox Code Playgroud)

}

so *_*ead 5

不知道您是否最近升级到最新版本的Selenium,但是由于Selenium 3.0,您还需要根据系统配置从下面的URL下载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");
Run Code Online (Sandbox Code Playgroud)