在Selenium的FirefoxOptions中设置BrowserExecutableLocation不会阻止“无法找到一组匹配的功能”错误 [英] Setting BrowserExecutableLocation in FirefoxOptions in Selenium doesn't prevent an "Unable to find a matching set of capabilities" error
问题描述
我尝试创建Firefox驱动程序的实例,如下所示:
var options = new FirefoxOptions )
{
BrowserExecutableLocation = @C:\ Program Files(x86)\ Mozilla Firefox \Firefox.exe,
Profile = new FirefoxProfile(),
LogLevel = FirefoxDriverLogLevel.Debug
};
firefoxDriver =新的FirefoxDriver(选项);
但是,当我运行测试时,出现以下错误: Unable找到一组匹配的功能
。我在堆栈溢出和其他地方读到的其他答案表明,解决这个问题的方法是显式指定二进制文件的位置,如下所示:
< (新的FirefoxBinary(@C:\程序文件(x86)\Mozilla Firefox \ firefox.exe),新的FirefoxProfile()); code> firefoxDriver = new FirefoxDriver
当我尝试这种方法时,它可以工作,但是我得到了下面的编译器警告:
警告CS0618'FirefoxDriver.FirefoxDriver(FirefoxBinary,FirefoxProfile)'已经过时:'FirefoxDriver不能用FirefoxBinary对象构建。改用FirefoxOptions。这个构造函数将会在将来的版本中被移除。
如果第二个版本能够运行,为什么第一个版本不能运行,因为我在 FirefoxOptions
中清楚地指定了 BrowserExecutableLocation
?有没有一种方法可以使我像第一种方式尝试工作,以避免使用第二个,不赞成使用的构造函数?
$ b FWIW,我使用Firefox 52.2.0 ,我的NuGet包设置如下:
< packages>
< package id =Selenium.Firefox.WebDriverversion =0.18.0targetFramework =net452/>
< package id =Selenium.WebDriverversion =3.4.0targetFramework =net452/>
< package id =Selenium.WebDriver.IEDriverversion =3.4.0targetFramework =net452/>
< / packages>
如果您尝试使用FirefoxOptions,这个构造函数:
pre code> FirefoxDriver(FirefoxDriverService服务,FirefoxOptions选项,TimeSpan commandTimeout);
对我而言,以下方法无效:
FirefoxDriverService服务= FirefoxDriverService.CreateDefaultService(Path to Gecko);
service.FirefoxBinaryPath = @C:\ Program Files \Mozilla Firefox\firefox.exe;
driver = new FirefoxDriver(service);
然而,以下效果很好:
FirefoxDriverService服务= FirefoxDriverService.CreateDefaultService(Gecko Path);
FirefoxOptions选项=新的FirefoxOptions();
options.BrowserExecutableLocation = @C:\ Program Files \Mozilla Firefox\firefox.exe;
driver = new FirefoxDriver(service,options,TimeSpan.FromMinutes(1));
I'm still fairly new to Selenium and am trying to create some minimally passing test cases (I guess you could call them the equivalent of a "hello world" program in a sense).
I tried to create an instance of the Firefox Driver like this:
var options = new FirefoxOptions()
{
BrowserExecutableLocation = @"C:\Program Files(x86)\Mozilla Firefox\Firefox.exe",
Profile = new FirefoxProfile(),
LogLevel = FirefoxDriverLogLevel.Debug
};
firefoxDriver = new FirefoxDriver(options);
However, when I ran the test, I got the following error: Unable to find a matching set of capabilities
. Several other answers I read on Stack Overflow and elsewhere suggested that the way to fix this is to explicitly specify the location of the binary file, like this:
firefoxDriver = new FirefoxDriver(new FirefoxBinary(@"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"), new FirefoxProfile());
When I try that, it works, but I get the following compiler warning:
Warning CS0618 'FirefoxDriver.FirefoxDriver(FirefoxBinary, FirefoxProfile)' is obsolete: 'FirefoxDriver should not be constructed with a FirefoxBinary object. Use FirefoxOptions instead. This constructor will be removed in a future release.'
If the second version works, why doesn't the first version work as well, given that I clearly specified the BrowserExecutableLocation
in FirefoxOptions
? Is there a way to make something like the first way I tried work in order to avoid using the second, deprecated constructor?
FWIW, I'm using Firefox 52.2.0, and my NuGet packages are set as follows:
<packages>
<package id="Selenium.Firefox.WebDriver" version="0.18.0" targetFramework="net452" />
<package id="Selenium.WebDriver" version="3.4.0" targetFramework="net452" />
<package id="Selenium.WebDriver.IEDriver" version="3.4.0" targetFramework="net452" />
</packages>
If you are trying to use FirefoxOptions in particular, try this constructor:
FirefoxDriver(FirefoxDriverService service, FirefoxOptions options, TimeSpan commandTimeout);
For me the following did not work:
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(Path to Gecko);
service.FirefoxBinaryPath = @"C:\Program Files\Mozilla Firefox\firefox.exe";
driver = new FirefoxDriver(service);
However the following works well:
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService("Gecko Path");
FirefoxOptions options = new FirefoxOptions();
options.BrowserExecutableLocation = @"C:\Program Files\Mozilla Firefox\firefox.exe";
driver = new FirefoxDriver(service, options, TimeSpan.FromMinutes(1));
这篇关于在Selenium的FirefoxOptions中设置BrowserExecutableLocation不会阻止“无法找到一组匹配的功能”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!