2012-02-28 91 views
9

有人可以告訴我如何在Selenium(C#)中設置firefox exe文件的路徑。Selenium Webdriver:爲Firefox exe指定文件路徑

我用下面的代碼目前,然而由於希望它不工作:

FirefoxProfile profile = new FirefoxProfile(); 

profile.SetPreference("webdriver.firefox.bin", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); 

IWebDriver driver = new FirefoxDriver(profile); 

任何建議,將不勝感激。

回答

7

您應該使用FirefoxBinary代替FirefoxProfile如下

FirefoxBinary binary = new FirefoxBinary('path/to/binary'); 
IWebDriver driver = new FirefoxDriver(binary); 
+6

這並不適合我,FirefoxDriver中沒有采用FirefoxBinary參數的ctor。此外,您的字符串被錯誤地引用。 – kai 2015-11-17 10:57:53

+0

有關此答案的一點更新,使用ctor FirefoxDriver(FirefoxBinary firefoxBinary,FirefoxProfile firefoxProfile)已過時。而是使用FirefoxOptions來設置驅動程序,並將對象傳遞給驅動程序FirefoxDriver 'ffOptions = new FirefoxOptions(); ffOptions.BrowserExecutableLocation = @「C:\ Firefox \ App \ Firefox \ firefox.exe」; driver = new FirefoxDriver(ffOptions);' – 2017-03-02 11:04:15

0

另一種選擇是配置的系統屬性。

System.setProperty("webdriver.firefox.bin",'path/to/binary'); 
相關問題