我注意到使用 Selenium Webdriver 使用配置文件打开 Firefox 与使用相同的配置文件手动打开 Firefox 有很多不同。主页不会在 Selenium Webdriver 驱动程序中加载,about:config 中的非 boolean 设置无法修改……仅举几个差异。有没有办法让 Selenium Webdriver 打开 Firefox 驱动程序与手动打开 Firefox 完全相同?
编辑:这是我当前用于健全性检查的代码......
File profileDirectory = new File("C:\\Users\\[UserName]\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\cox74xm7.default");
FirefoxProfile ffprofile = new FirefoxProfile(profileDirectory);
WebDriver ffdriver = new FirefoxDriver(ffprofile);
最佳答案
您需要实例化FirefoxProfile
并将其传递给 WebDriver
构造函数:
File profileDirectory = new File(path);
FirefoxProfile profile = new FirefoxProfile(profileDirectory);
WebDriver webDriver = new FirefoxDriver(profile);
其中 path
是您现有配置文件的路径。
关于java - 如何使 Firefox 驱动程序与手动打开 Firefox 一样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26914737/