1

私はまだSeleniumを初めて使用しており、最小限のテストケースを作成しようとしていますある意味での「こんにちは世界」プログラムに相当する)。SeleniumのFirefoxOptionsでBrowserExecutableLocationを設定しても「一致する機能セットが見つかりません」エラー

私はこのようなFirefoxのドライバのインスタンスを作成しようとしました:

var options = new FirefoxOptions() 
{ 
    BrowserExecutableLocation = @"C:\Program Files(x86)\Mozilla Firefox\Firefox.exe", 
    Profile = new FirefoxProfile(), 
    LogLevel = FirefoxDriverLogLevel.Debug 
}; 

firefoxDriver = new FirefoxDriver(options); 

私がテストを実行したときにしかし、私は次のエラーを得た:Unable to find a matching set of capabilities。私は他の場所でスタックオーバーフローに読んで、いくつかの他の答えは、この問題を解決する方法は、明示的にこのように、バイナリファイルの場所を指定することであることが示唆された:

firefoxDriver = new FirefoxDriver(new FirefoxBinary(@"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"), new FirefoxProfile()); 

私はそれが動作する、ことをしようと、私は取得する場合次のコンパイラの警告:番目のバージョンが動作する場合

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.'

は、なぜ最初のバージョンの仕事だけでなく、私ははっきりFirefoxOptionsBrowserExecutableLocationが指定されていることを与えられたのでしょうか? 2番目の非推奨コンストラクタの使用を避けるために、私が仕事を試した最初の方法のようなものを作る方法はありますか?

FWIW、私は、Firefox 52.2.0を使用していて、次のように私のNuGetパッケージが設定されています。

<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> 

答えて

1

あなたが特にFirefoxOptionsを使用しようとしている場合は、このコンストラクタを試してみてください。

FirefoxDriver(FirefoxDriverService service, FirefoxOptions options, TimeSpan commandTimeout); 

私にとって以下は動作しませんでした:

FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(Path to Gecko); 
service.FirefoxBinaryPath = @"C:\Program Files\Mozilla Firefox\firefox.exe"; 
driver = new FirefoxDriver(service); 

次はうまく機能が:

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)); 
+0

ありがとう、それは私のためにも働くようです。 – EJoshuaS

関連する問題