java - 获取 Firefox ProfilesIni 的配置文件,当配置文件计数超过 3(包括默认值)时不选择给定的配置文件

标签 java selenium selenium-webdriver selenium-firefoxdriver

当我有 3 个(随机创建的)自定义 FF 配置文件和 1 个默认配置文件时,下面的代码没有更改 FF 配置文件。

WebDriver driver;
    String profilepath = "<user Dir>/Local/Mozilla/Firefox/Profiles/";
    ProfilesIni profilesini = new ProfilesIni();
    FirefoxProfile firefoxprofile = new FirefoxProfile(new File(profilepath));
    firefoxprofile = profilesini.getProfile("profile_1");
    driver = new FirefoxDriver(firefoxprofile);

FF 配置文件为:profile_1、profile_2 和 profile_3。当我运行使用“profile_2 或默认值”启动的代码 FF 时。不包含传递的配置文件名称 (profile_1)

我在 Win 10 64 位上使用 selenium-sever 独立版 2.53.0 和 FF 46.0。

最佳答案

如果您想启动自定义 Firefox 配置文件。这就是你的做法。

首先创建一个 ProfilesIni 对象,然后使用 getProfile() 获取所需的 firefox 配置文件,然后将该特定配置文件传递给WebDriver 初始化。

ProfilesIni profiles = new ProfilesIni();
FirefoxProfile profile = profiles.getProfile("profile_1");
WebDriver driver = new FirefoxDriver(profile);

希望对你有帮助!

关于java - 获取 Firefox ProfilesIni 的配置文件,当配置文件计数超过 3(包括默认值)时不选择给定的配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36971914/

相关文章:

java - Cassandra 中的超时异常

java - 如何使用 WebDriver 查找按钮?

Python:类型 'bytes' 的对象不可 JSON 序列化

excel - SeleniumBasic VBA 使用 WebElement 方法最快的 WebElement 循环

python - 当浏览器到达网页底部时无法退出循环

python - 无法从网页中获取文本

java - 嵌入式 Jetty 应用程序中出现 500 错误

java - 自动从实例转到eclipse中的某个类

java - 线程 "main"java.util.NoSuchElementException 中的异常(我对此很陌生)

javascript - 是否可以使用 Protractor 来测试任何非 AngularJS 应用程序?