Java 如何使用 Selenium 2 Webdriver 打开指定的配置文件 Firefox?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20543013/
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 open specified profile Firefox with Selenium 2 Webdriver?
提问by user3095228
When I use default profile starts without problem. But when i starts with custom profile, firefox starts but stays "blocked". The process remains active consuming 31MB of RAM, but never start. Only start if I killed the process, then starts and works fine with selenium.
当我使用默认配置文件启动时没有问题。但是当我从自定义配置文件开始时,firefox 启动但保持“被阻止”。该进程保持活动状态,消耗 31MB 的 RAM,但从未启动。只有在我终止进程时才启动,然后启动并使用 selenium 正常工作。
I use Windows 7, Firefox 25.0.1 and selenium-server-standalone-2.38.0.jar ?Maybe problems with compatibility of versions?
我使用 Windows 7、Firefox 25.0.1 和 selenium-server-standalone-2.38.0.jar ?也许版本兼容性有问题?
This is the code to open the profile:
这是打开配置文件的代码:
FirefoxProfile profile = new FirefoxProfile(new File("C:/Users/UserTest/AppData/Roaming/Mozilla/Firefox/Profiles/tydtn9km.testprofile"));
WebDriver driver = new FirefoxDriver(profile);
Edit: This is my actual code
编辑:这是我的实际代码
package org.openqa.selenium.example;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
public class Main {
public static void main(String[] args) {
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.getProfile("Other");
WebDriver driver = new FirefoxDriver(ffprofile);
driver.get("http://google.com");
}
}
Edit 2: ResolvedThe problem ocurred because my Firefox profile is located in another partition, and Firefox in the other partition.
编辑 2:已解决出现问题是因为我的 Firefox 配置文件位于另一个分区,而 Firefox 位于另一个分区。
回答by Pavel Janicek
I have been using it like this:
我一直这样使用它:
First, create a Firefox profile and name it somehow you know. E.g. SELENIUM
首先,创建一个 Firefox 配置文件并以您知道的方式命名。例如SELENIUM
Then initialize your profile:
然后初始化您的个人资料:
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.getProfile("SELENIUM");
WebDriver driver = new FirefoxDriver(ffprofile);