java - 是否可以在保存的密码中创建 Firefox 配置文件和密码?

标签 java selenium firefox selenium-webdriver firefox-profile

是否可以将密码添加到作为 org.openqa.selenium.firefox.FirefoxProfile 实例创建的配置文件中? ?

从 Mozilla 文档 ( Profiles — Where Firefox stores your bookmarks, passwords and other user data ),我可以看到 Firefox 将密码存储在两个文件中:

但是在 FirefoxProfile 类中看不到任何方法来单独将密码添加到配置文件,或者传递像 logins.json/ 这样的文件key3.db。 (我在链接的 Mozilla 页面上也找不到任何内容,这些页面似乎以普通用户的身份存储密码,而不是以编程方式存储密码)

在我的 Selenium 测试套件中,我正在代码中动态创建一个 Firefox 配置文件,但我必须将密码(例如,对于开发服务器上的 HTTP Basic Auth)编码成这样的 URL:

http://user:pass@localhost/example.html

(我知道我可以创建一个完整的配置文件并将其添加到 Git,以便传递,但如果可以的话我想避免这种情况)

最佳答案

我通读了 selenium firefoxprofile code for v53.0并没有看到任何明显的东西。但是,您可以 copy those two files from the existing profile进入 selenium 创建的默认配置文件。您只需要新生成的默认 firefoxprofile 的位置,您可以在执行时(动态地)获取它:

FirefoxProfile profile = new FirefoxProfile();
System.out.println(">> path to profile=" + profile.layoutOnDisk().getAbsolutePath());
// Copy the two files
WebDriver driver = new FirefoxDriver(profile);

关于java - 是否可以在保存的密码中创建 Firefox 配置文件和密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40584791/

相关文章:

java - wicket ajaxformcomponentupdatingbehavior 通过单击按钮获取 TextField 的值

java - 使用静态方法执行文件 I/O 时出现 NotSerializableException

java - 是什么导致了 java.lang.ArrayIndexOutOfBoundsException 异常?我该如何预防?

java - 使用 TwitterStream 对推文进行采样是否正常,如 Twitter4J 代码示例中所示,我主要得到的只是问号作为用户名和状态?

python - 使用 switch_to_windows() 并打印标题的 Selenium webdriver 不会打印标题。

python - 如何使用 Selenium (Python) 进行 Google 搜索,然后在新选项卡中打开第一页的结果?

python - 使用 Selenium 下载 google 文档

javascript - Twitter "tweet this"按钮在 Firefox 中显示为按钮,在 Chrome 中只是一个链接

javascript - 动态解除绑定(bind)XBL的动态方式

javascript - 在 Firefox 中,一元运算符函数表达式比括号函数表达式快约 5261%