如何在 Selenium 中使用自定义 Firefox 配置文件?(Java) (并通过 HTML 授权窗口)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14458289/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use custom Firefox Profile with Selenium? (Java) (And pass HTML Authorization Window)
提问by Koray Tugay
How can I use Selenium with Java with a custom Firefox Profile?
如何通过自定义 Firefox 配置文件将 Selenium 与 Java 结合使用?
采纳答案by Koray Tugay
I have spent a day trying to do this and decided to share it here. There is some information on the web as well but most of them are a bit complicated or not up to date...
我花了一天的时间试图做到这一点,并决定在这里分享。网络上也有一些信息,但大多数都有些复杂或不是最新的...
Here is my configuration:
这是我的配置:
Firefox version: 12
Selenium version: 2.25
Language: Java
Platform: MacOS
- Open Terminal
- type:
/Applications/Firefox.app/Contents/MacOS/firefox-bin -p
( change the path as necessary ) - Create a new profile, save it in a directory as you wish..
- Start firefox with this profile, add any add-ons, modifications as you wish.
- In Selenium, use:
- 打开终端
- 输入:(
/Applications/Firefox.app/Contents/MacOS/firefox-bin -p
根据需要更改路径) - 创建一个新的配置文件,根据需要将其保存在目录中..
- 使用此配置文件启动 Firefox,根据需要添加任何附加组件和修改。
- 在硒中,使用:
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);
Again here change the absolute path as required. Add add-ons like autoAuth to pass the HTML Authorization windows in Firefox to this profile..
这里再次根据需要更改绝对路径。添加诸如 autoAuth 之类的附加组件,以将 Firefox 中的 HTML 授权窗口传递到此配置文件。
回答by Ravi
For Windows, to create a new Firefox Profile, type:
对于 Windows,要创建新的 Firefox 配置文件,请键入:
firefox -profilemanager
in Run that will open the Firefox Profile Manager.
在运行中,将打开 Firefox 配置文件管理器。
Let's say you have created a profile called Selenium
, then you can use the following code:
假设您创建了一个名为 的配置文件Selenium
,那么您可以使用以下代码:
ProfilesIni listProfiles = new ProfilesIni();
FirefoxProfile profile = listProfiles.getProfile("Selenium");
WebDriver driver = new FirefoxDriver(profile);