Selenium WebDriver(又称Selenium 2)在打开FirefoxDriver时使用的匿名配置文件从何处获取?如果它使用的是Firefox的默认配置文件目录%appdata%/roaming/mozilla/firefox/profiles,那么如果我禁用了Firefox插件,那么对于Selenium WebDriver也应该被禁用,那为什么没有呢?
Selenium WebDriver(又称Selenium 2)在打开FirefoxDriver时使用的匿名配置文件从何处获取?如果它使用的是Firefox的默认配置文件目录%appdata%/roaming/mozilla/firefox/profiles,那么如果我禁用了Firefox插件,那么对于Selenium WebDriver也应该被禁用,那为什么没有呢?
我来回答这个问题,并支持@twall的评论:在使用Selenium 2 WebDriver启动Firefox时,它会启动一个新的匿名配置文件。
但是,如果您想要更改它,您可以创建新的Firefox配置文件并命名为某种方式,你知道它是什么 - 例如SELENIUM
。
然后在您的代码中执行以下操作:
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.getProfile("SELENIUM");
WebDriver driver = new FirefoxDriver(ffprofile);
这样,Firefox将始终启动该配置文件。您可以在该配置文件中进行所有所需的设置。
请注意,webdriver.firefox.profile的值必须是Firefox配置文件的名称,而不是位置或文件夹名称。java -jar selenium-server-standalone-2.37.0.jar -Dwebdriver.firefox.profile=my-profile -role node -hub http://example-server.org:4444/grid/register
private FirefoxProfile GetFirefoxProfile()
{
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.SetPreference("network.automatic-ntlm-auth.trusted-uris", "http://localhost");
return firefoxProfile;
}
ProfilesIni profileini = new ProfilesIni() {
@Override
public FirefoxProfile getProfile(String profileName) {
File appData = locateAppDataDirectory(Platform.getCurrent());
Map<String, File> profiles = readProfiles(appData);
File profileDir = profiles.get(profileName);
if (profileDir == null)
return null;
return new FirefoxProfile(profileDir);
}
};
FirefoxProfile profile = profileini.getProfile("CustomSeleniumProfile");
//profile.setEnableNativeEvents(false);
driver = new FirefoxDriver(profile);
//ffDriver.manage().deleteAllCookies();
driver.get("http://www.google.com");