【问题标题】:How can I retain my Firefox profile's cache with Geckodriver?如何使用 Geckodriver 保留 Firefox 配置文件的缓存?
【发布时间】:2018-10-23 18:49:21
【问题描述】:

我需要使用 Selenium 和 Geckodriver 保留我的缓存。我有一个 Firefox 配置文件,我在 Geckodriver 启动时加载它:

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

这按预期工作,但它复制缓存。转到about:cache,它是空的。我想保留我的缓存,我想直接使用我的个人资料。目前Selenium/Geckodriver 复制部分配置文件并使用它,但不使用缓存。

使用Geckodriver 时如何保留缓存​​?

【问题讨论】:

  • 你的用例到底是什么?你打算用cache 做什么?请提供相关的 HTML 和您的代码试用版。

标签: java selenium firefox selenium-webdriver geckodriver


【解决方案1】:

我正在使用现有的自定义 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();

我的缓存“增长”正常。

如果零缓存仍然存在,请检查 Firefox 配置文件的设置(关闭时删除缓存)。

【讨论】:

    【解决方案2】:

    想出了解决办法。

    使用此加载配置文件不起作用:

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

    对我来说,这确实有效:

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

    我现在有了正确的完整缓存。

    【讨论】:

      猜你喜欢
      • 2021-11-28
      • 1970-01-01
      • 2018-01-13
      • 1970-01-01
      • 2021-08-06
      • 2020-08-31
      • 2019-08-30
      • 2012-09-27
      • 2021-04-10
      相关资源
      最近更新 更多