我无法让 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/