Kor*_*gay 6

我花了一天时间尝试这样做,并决定在这里分享.网上也有一些信息,但大多数都有点复杂或不是最新的......

Here is my configuration:
Firefox version: 12
Selenium version: 2.25
Language: Java
Computer: Macintosh
Run Code Online (Sandbox Code Playgroud)
  1. 开放式终端
  2. 键入:/Applications/Firefox.app/Contents/MacOS/firefox-bin -p(根据需要更改路径)
  3. 创建一个新的配置文件,将其保存在您希望的目录中..
  4. 使用此配置文件启动firefox,添加任何插件,根据需要进行修改.
  5. 在Selenium中,使用:

 FirefoxBinary binary = new FirefoxBinary();  
 File firefoxProfileFolder = new 
 File("/Users/xxx/work/xxx/selenium/src/test/resources/firefoxprofile");
 FirefoxProfile profile = new FirefoxProfile(firefoxProfileFolder);
 profile.setAcceptUntrustedCertificates(true);
 webDriver = new FirefoxDriver(binary, profile);
Run Code Online (Sandbox Code Playgroud)

再次根据需要更改绝对路径.添加autoAuth等附加组件,将Firefox中的HTML授权窗口传递给此配置文件.

  • 你今天节省了我的一天:)我希望我可以给10个upvotes. (2认同)

小智 6

对于Windows,要创建新的Firefox配置文件,请键入:

firefox -profilemanager
Run Code Online (Sandbox Code Playgroud)

在运行中将打开Firefox配置文件管理器.

假设您创建了一个名为的配置文件Selenium,那么您可以使用以下代码:

ProfilesIni listProfiles = new ProfilesIni();
FirefoxProfile profile = listProfiles.getProfile("Selenium");
WebDriver driver = new FirefoxDriver(profile);
Run Code Online (Sandbox Code Playgroud)