
Remove-CacheFiles " $waterfoxAppDataPath\ $cachePath " $firefoxAppDataPath = ( Get-ChildItem "C:\users\ $user\AppData\Local\Mozilla\Firefox\Profiles " | Where-Object ).FullName $possibleCachePaths = 'cache ', 'cache2\entries ', 'thumbnails ', 'cookies.sqlite ', 'webappsstore.sqlite ', 'chromeappstore.sqlite ') If(( Test-Path "C:\users\ $user\AppData\Local\Mozilla\Firefox\Profiles ")) Remove-CacheFiles " $chromeAppData\ $cachePath "įorEach( $localUser in ( Get-ChildItem 'C:\users ').Name) $possibleCachePaths = 'Cache ', 'Cache2\entries\ ', 'Cookies ', 'History ', 'Top Sites ', 'VisitedLinks ', 'Web Data ', 'Media Cache ', 'Cookies-Journal ', 'ChromeDWriteFontCache ')įorEach( $cachePath in $possibleCachePaths) $chromeAppData = "C:\Users\ $user\AppData\Local\Google\Chrome\User Data\Default " If(( Test-Path "C:\users\ $user\AppData\Local\Google\Chrome\User Data\Default "))

Remove-CacheFiles "C:\Users\ $user\AppData\Local\Microsoft\Windows\Temporary Internet Files "Ĭ:\Windows\System32\ rundll32.exe InetCpl.cpl, ClearMyTracksByProcess 255Ĭ:\Windows\System32\ rundll32.exe InetCpl.cpl, ClearMyTracksByProcess 4351 Remove-CacheFiles "C:\Users\ $user\AppData\Local\Microsoft\Windows\WER " Remove-CacheFiles "C:\Users\ $user\AppData\Local\Temp "

Google chrome clear cache only how to#
It’s relatively straight forward once you see how it’s done, but I could find any information out there on how to accomplish it.#-# The key for all of these is just to use /deep/ in the selectors to get through the shadow root.Īnyway, if you found this from Google then I hope you found it helpful! Similarly, you can select or unselect the various checkboxes to control “Browsing history,” “Download history,” “Cached Images and files,” “Cookies and other site data,” “Password,” “Autofill form data,” “Hosted app data,” and “Media licenses.” This is probably more than enough for most testing scenarios, but you can easily modify the value of select#dropdownMenu to select other options. The default behavior is to only clear the cache from the last hour. It’s worth noting, that you can easily extend this to include more fine-grained control.
Google chrome clear cache only update#
If you execute it, by using from selenium import webdriverįor example, then you can the UI update as the cache is cleared. This clear_cache(driver) method will clear the browsing data in the same way that a user would. Wait.until_not(get_clear_browsing_button) # wait for the button to be gone before returning Get_clear_browsing_button(driver).click() """Clear the cookies and cache for the ChromeDriver instance."""ĭriver.get('chrome://settings/clearBrowserData') Return driver.find_element_by_css_selector('* /deep/ #clearBrowsingDataConfirm') """Find the "CLEAR BROWSING BUTTON" on the Chrome settings page.""" We can use this to construct a method for clearing the cache which also handles explicit waits for us. The magic selector in this case is * /deep/ #clearBrowsingDataConfirm. While these things are great for development, they can be a little bit of a headache when dealing with Selenium because of the shadow roots.įortunately, if we execute our query selector using the /deep/ combinator, we’re able to pierce through the shadow roots. Unfortunately, this won’t work because the Chrome settings page uses Polymer and WebComponents. Your first thought might be that you can call driver.find_element_by_id('clearBrowsingDataConfirm').click() here to find the DOM element and click it. We can see that the button’s id is clearBrowsingDataConfirm. This will highlight the button element and allow us to find its id.

We can right click on the button and then click on “Inspect” to open the Chrome Developer Tools. Then it’s just a matter of clicking the “CLEAR BROWSER DATA” button to actually clear the cache. You can navigate to this same page with Selenium by executing driver.get('chrome://settings/clearBrowserData'). If you navigate to chrome://settings/clearBrowserData in a Chrome browser then you’ll see something that looks like this. Luckily, if you get a bit creative then you can accomplish the same thing by using Selenium to interact with Chrome’s setting interface. The functionality to clear the cache directly is unfortunately not built into the WebDriver specification. There are however times when this method loses other state that you may want to preserve. The fresh instance of Chrome will start with a clean browser history, cookies, and cache. You can of course call driver.close() on your current ChromeDriver instance and then provision a new one. Sometimes during the course of testing or web scraping with Google Chrome, you might desire to clear the browser cache and cookies with Selenium.
