Selenium Webdriver:指定Firefox exe的文件路径

sta*_*101 10 .net c# selenium webdriver

有人可以告诉我如何在Selenium(C#)中设置firefox exe文件的路径.

我目前正在使用以下代码,但它没有按预期工作:

 FirefoxProfile profile = new FirefoxProfile();

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

 IWebDriver driver = new FirefoxDriver(profile);
Run Code Online (Sandbox Code Playgroud)

任何建议,将不胜感激.

Aut*_*ter 7

您应该使用FirefoxBinary而不是FirefoxProfile,如下所示

FirefoxBinary binary = new FirefoxBinary(new File("path/to/binary"));

FirefoxOptions options = new FirefoxOptions();
options.setBinary(binary);

IWebDriver driver = new FirefoxDriver(options);
Run Code Online (Sandbox Code Playgroud)

  • 这不适合我,FirefoxDriver中没有采用FirefoxBinary参数的ctor.此外,您的字符串被错误引用. (7认同)
  • 使用ctor FirefoxDriver(FirefoxBinary firefoxBinary,FirefoxProfile firefoxProfile)关于此答案的一些更新已过时。而是使用FirefoxOptions来设置驱动程序并将对象传递给ctor FirefoxDriver`ffOptions = new FirefoxOptions();。ffOptions.BrowserExecutableLocation = @“ C:\ Firefox \ App \ Firefox \ firefox.exe”; driver = new FirefoxDriver(ffOptions);` (2认同)