在运行时获取Firefox配置文件名称并设置首选项

时间:2014-06-06 05:33:28

标签: firefox selenium webdriver

我有一个场景来处理我使用Selenium Webdriver打开Firefox浏览器的位置,每次打开一个新的配置文件。代码如下:

WebDriver driver = new FirefoxDriver();

每次打开一个新的配置文件,例如: anonymous8958670169066009851webdriver-profile ,每次WebDriver打开Firefox浏览器时,配置文件名称都会更改。我的目的是在运行时获取配置文件名称并设置一些首选项,如处理无响应的JS警报等。基本上流程将如下所示:

WebDriver driver = new FirefoxDriver();
<Write some code here to get Firefox profile name>
<Set profile settings like **profile.setPreference("extensions.firebug.currentVersion", "1.8.1");>

请在第二步帮助我,即在这里写一些代码以获取Firefox个人资料名称,如果有人之前已经取得类似的东西。

1 个答案:

答案 0 :(得分:1)

你正在向后接近这个问题。正确的做法是自己创建FirefoxProfile对象,并在FirefoxDriver的构造函数中使用它。代码看起来像这样:

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("extensions.firebug.currentVersion", "1.8.1");
WebDriver driver = new FirefoxDriver(profile);