简体   繁体   English

如何使用Geckodriver保留Firefox配置文件的缓存?

[英]How can I retain my Firefox profile's cache with Geckodriver?

I need to retain my cache with Selenium and Geckodriver . 我需要使用Selenium和Geckodriver保留我的缓存。 I have a Firefox profile and I load it upon startup of Geckodriver : 我有一个Firefox配置文件,并在启动Geckodriver时加载了它:

ProfilesIni profilesIni = new ProfilesIni();
FirefoxProfile firefoxProfile = profilesIni.getProfile("profile-name");
firefoxOptions.setProfile(firefoxProfile);

This works as it is meant to, but it does not copy the cache. 这可以按预期的方式工作,但不会复制缓存。 Going to about:cache , it's empty. 转到about:cache ,它是空的。 I want to retain my cache, I want to use my profile directly. 我想保留我的缓存,我想直接使用我的个人资料。 Currently Selenium/Geckodriver copies part of the profile and uses that, but not the cache. 当前, Selenium/Geckodriver复制一部分配置文件并使用该配置文件,但不使用缓存。

How am I able to keep my cache when using Geckodriver ? 使用Geckodriver时如何保留我的缓存?

I'm using existing custom Firefox profile with this code (to be complete): 我将现有的自定义Firefox配置文件与以下代码结合使用(完整):

FirefoxOptions options = new FirefoxOptions();

ProfilesIni allProfiles = new ProfilesIni();         
FirefoxProfile selenium_profile = allProfiles.getProfile("selenium_profile");
options.setProfile(selenium_profile);

options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
System.setProperty("webdriver.gecko.driver", "C:\\Users\\pburgr\\Desktop\\geckodriver-v0.20.0-win64\\geckodriver.exe");
driver = new FirefoxDriver(options);
driver.manage().window().maximize();

and my cache "grows" normaly. 和我的缓存正常“增长”。

If zero cache persists, check the setting of the Firefox profile (delete cache when closing). 如果零缓存仍然存在,请检查Firefox配置文件的设置(关闭时删除缓存)。

Figured out the solution. 找出解决方案。

Loading the profile using this does not work: 使用此方法加载配置文件不起作用:

FirefoxProfile firefoxProfile = profilesIni.getProfile("profile-name");

For me, this did however work: 对我来说,这确实有效:

String profilePath = "C\\Users\\Name\\AppData\\Local\\Mozilla\\Firefox\\Profiles\\myprofile";
FirefoxProfile firefoxProfile = new FirefoxProfile(new File(profilePath));

I now have my correct, full cache. 现在,我有了正确的完整缓存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在Java中使用geckodriver启动FireFox自定义配置文件 - unable to launch FireFox custom profile with geckodriver in java 我如何保留我的下拉选择 - how can i retain my dropdown selection 如何使用 Geckodriver 在 Selenium 中禁用 Firefox 登录? - How do I disable Firefox logging in Selenium using Geckodriver? 如何在Selenium Webdriver 3中为Firefox驱动程序设置默认配置文件? - How can I set a default profile for the Firefox driver in Selenium Webdriver 3? 如何保留ImageIcon的文件名以供以后参考? - How can I retain an ImageIcon's file name for later reference? 如何通过GeckoDriver和Selenium启动Firefox浏览器 - How to launch Firefox browser through GeckoDriver and Selenium 如何使用 GeckoDriver Firefox 和 Selenium 下载文件? - How to download files using GeckoDriver Firefox and Selenium? JavaScript 错误:resource://gre/modules/XULStore.jsm,第 66 行:错误:使用 GeckoDriver Firefox 和 ZC49DFB55F06BB406E2C5CA786F5Z5 时找不到配置文件目录错误 - JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory error using GeckoDriver Firefox and Selenium 更改设备配置文件后如何触发事件? - How can I trigger an event when the device's profile is changed? 如何使用Intent打开用户的个人资料联系人? - How can I open the user's profile contact using an Intent?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM