开箱即用,我无法让硒网格工作。我有selenium服务器3.4.0和以下代码产生显示的错误
收到错误
An unhandled exception of type 'System.InvalidOperationException' occurred in WebDriver.dll
Additional information: The path to the driver executable must be set by the
webdriver.gecko.driver system property; for more information, see
https://github.com/mozilla/geckodriver. The latest version can be downloaded
from https://github.com/mozilla/geckodriver/releases
简单代码
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Remote;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var url = new Uri("http://10.6.122.49:5555/wd/hub");
var options = new FirefoxOptions();
options.SetPreference("webdriver.gecko.driver", @"D:\geckodriver.exe");
var driver = new RemoteWebDriver(url, options.ToCapabilities());
driver.Navigate().GoToUrl("http://www.google.com");
}
}
}
更新
答案 0 :(得分:1)
我在这里用清楚的例子解释,相应地做出改变
注意:确保在开始之前执行此操作。
您可以从此位置下载Geckodriver https://github.com/mozilla/geckodriver/releases
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Support;
using OpenQA.Selenium.Support.UI;
using NUnit.Framework;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Chrome;
namespace ClassLibrary2
{
public class Class1
{
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(@"D:\dev1"); // location of the geckdriver.exe file
[Test]
public void GeckoDriverImplementation()
{
IWebDriver driver = new FirefoxDriver(service);
driver.Navigate().GoToUrl("https://google.com/");
}
}
}
答案 1 :(得分:0)
在系统变量下添加名称为:webdriver.gecko.driver和value = D:\ geckodriver.exe的环境变量。你可以安全地删除
options.SetPreference("webdriver.gecko.driver", @"D:\geckodriver.exe");
希望这有帮助
答案 2 :(得分:0)
在C#中
Environment.SetEnvironmentVariable("webdriver.gecko.driver", @"C:\full\path\to\geckodriver.exe");