【发布时间】:2017-04-06 11:07:40
【问题描述】:
我正在尝试从 Selenium 2 升级到 Selenium 3,但是非常简单快速的旧处理方式不再起作用(并且文档似乎不存在)
这是目前的程序,我想要的是使用配置文件打开一个 Firefox 驱动程序:SELENIUM
遗憾的是它不起作用并且总是因错误而关闭:
“System.InvalidOperationException”类型的未处理异常 > 发生在 WebDriver.dll 中
附加信息:损坏的 deflate 流
这是我目前的程序:
public Program()
{
FirefoxOptions _options = new FirefoxOptions();
FirefoxProfileManager _profileIni = new FirefoxProfileManager();
FirefoxDriverService _service = FirefoxDriverService.CreateDefaultService(@"C:\Programme\IMaT\Output\Release\Bin");
_service.FirefoxBinaryPath = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
try
{
if ((_options.Profile = _profileIni.GetProfile("SELENIUM")) == null)
{
Console.WriteLine("SELENIUM PROFILE NOT FOUND");
_profile.SetPreference("network.proxy.type", 0); // disable proxy
_profile = new FirefoxProfile();
}
}
catch
{
throw new Exception("Firefox needs a Profile with \"SELENIUM\"");
}
IWebDriver driver = new FirefoxDriver(_service,_options,new System.TimeSpan(0,0,30));
driver.Navigate().GoToUrl("ld-hybrid.fronius.com");
Console.Write("rtest");
}
static void Main(string[] args)
{
new Program();
}
无需加载配置文件,它只适用于新的 FirefoxDriver(_service),但配置文件是强制性的。
在 Selenium 2 中,我使用以下代码处理它:
FirefoxProfileManager _profileIni = new FirefoxProfileManager();
// use custom temporary profile
try {
if ((_profile = _profileIni.GetProfile("SELENIUM")) == null)
{
Console.WriteLine("SELENIUM PROFILE NOT FOUND");
_profile.SetPreference("network.proxy.type", 0); // disable proxy
_profile = new FirefoxProfile();
}
}
catch
{
throw new Exception("Firefox needs a Profile with \"SELENIUM\"");
}
_profile.SetPreference("intl.accept_languages", _languageConfig);
_driver = new FirefoxDriver(_profile);
快速简单,但由于驱动程序不支持具有服务和配置文件的构造函数,我真的不知道如何使其工作,任何帮助将不胜感激
【问题讨论】:
标签: c# .net selenium firefox selenium-webdriver