我有一个使用 Java + Selenium WebDriver 的工具,我每天都运行它。如何像普通浏览器一样导出 cookie、历史记录...并导入/重用它以供下次执行。
最佳答案
我们可以将浏览器的配置文件信息写入 JSON 文件,然后使用相同的配置文件实例化新浏览器。
FirefoxProfile类提供toJson()方法来写入配置文件信息
FirefoxProfile 类提供 fromJson() 方法来检索配置文件信息
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(
new File("src/test/resources/extensions/anyextenstion.file"));
String json = profile.toJson();
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setProfile(FirefoxProfile.fromJson(json));
FirefoxDriver driver = new FirefoxDriver(firefoxOptions);
关于java - 如何使用 Java + Selenium WebDriver 导出/导入 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52158777/