簡體   English   中英

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

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

我需要使用Selenium和Geckodriver保留我的緩存。 我有一個Firefox配置文件,並在啟動Geckodriver時加載了它:

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

這可以按預期的方式工作,但不會復制緩存。 轉到about:cache ,它是空的。 我想保留我的緩存,我想直接使用我的個人資料。 當前, Selenium/Geckodriver復制一部分配置文件並使用該配置文件,但不使用緩存。

使用Geckodriver時如何保留我的緩存?

我將現有的自定義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配置文件的設置(關閉時刪除緩存)。

找出解決方案。

使用此方法加載配置文件不起作用:

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

對我來說,這確實有效:

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

現在,我有了正確的完整緩存。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM