1

我對Selenium還是比較新的,並且正在嘗試創建一些最低限度傳遞的測試用例(我想你可以稱它們爲在某種意義上相當於「hello world」程序)。在Selenium中設置BrowserExecutableLocation在FirefoxOptions中並不能阻止「無法找到匹配的一組功能」錯誤

我試圖像這樣創造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?有沒有辦法讓事情像我嘗試工作的第一種方式一樣,以避免使用第二個不推薦使用的構造函數?

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

相關問題