如何让Firefox在Mac OSX上使用Selenium WebDriver

Asp*_*ant 15 java macos firefox selenium webdriver

我正在尝试配置代理设置,WebDriver所以我使用了以下代码....

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", 1);
profile.setPreference("network.proxy.http","207.229.122.162");
profile.setPreference("network.proxy.http_port", 3128); 
WebDriver driver = new FirefoxDriver(profile);
selenium = new WebDriverBackedSelenium(driver, "http://www.example.com/");
Run Code Online (Sandbox Code Playgroud)

并且在对文件执行运行后,我得到例外...

org.openqa.selenium.WebDriverException:在PATH中找不到firefox二进制文件.

确保安装了firefox.操作系统似乎是:MAC

系统信息:os.name:'Mac OS X',os.arch:'x86_64',os.version:'10 .6.8',

java.version:'1.6.0_29'

驱动程序信息:driver.version:FirefoxDriver

任何人都可以帮助我解决如何以及在何处提供路径 firefoxprofile()

Pet*_*ček 18

我相信你有几个选择:

在PATH系统变量中指定文件夹(Firefox二进制文件所在的文件夹) - 这是方法.

或者打电话

WebDriver driver = new FirefoxDriver(new FirefoxBinary(new File("path/to/your/firefox.exe")), profile);
Run Code Online (Sandbox Code Playgroud)


小智 11

对于Mac,如果您通过brew cask安装FireFox,只需将其符号链接到/ Applications.

cd /Applications
ln -s /Users/<your-username>/Applications/Firefox.app Firefox.app
Run Code Online (Sandbox Code Playgroud)

这对我有用.