Forum Discussion

nwalimbe's avatar
Occasional Contributor
7 years ago

How to clear browser cache in firefox and chrome

Before I login to the application, I want the ability to clear the cache. This is because the passwords and urls etc are stored in cache and before I execute any tests, I need to ensure that the cache is cleared. I am writing in python script. Is it possible? If yes, how?

8 Replies

    • nwalimbe's avatar
      Occasional Contributor

      Thanks a lot shankar_r. However this seems to be in a language I do not understand. Could you pls. convert it into python or give me some pointers. I tried googling it, but looks like I am making mistakes here and there.



      • nwalimbe's avatar
        Occasional Contributor

        This is the code, I am trying to use:


        def ClearAllChromeStoredInfo():

        objFSO = CreateObject("Scripting.FileSystemObject")
        strAppDataFolder = aqEnvironment.GetEnvironmentVariable(("LocalAppData") & "\Google\Chrome\User Data\Default")
        FilesInFolder = objFSO.GetFolder(strAppDataFolder).Files
        FoldersInFolder = objFSO.GetFolder(strAppDataFolder).SubFolders
        for Folder in FoldersInFolder:
        if UCase(Folder.Name) = "EXTENSIONS" and LCase(Folder.Name) = "EXTENSION STATE"
        Folder.Delete True
        For File In range (FilesInFolder)
        If Not UCase(File.Name) = "PREFERENCES"


        The error I am getting is attached.

    • shankar_r's avatar
      Community Hero

      AlexKaras I am admiring wherever i see old threads there i see you in comments which insist me how much you are contributing for the peoples in the community to get away from automation headaches. :smileyhappy:

  • Hi!


    There is a workaround using Keys() method of browser Page object. Sorry, I'm not familiar with Python but in JScript it looks like following:


    var browser = Sys.Find('ProcessName', 'chrome');

    var page = browser.Page('http://yourpage.url/');

    page.Keys("!^[Del]"); // Ctrl + Shift + Delete keys combination opens clear browser data dialog

    browser.Page('chrome://settings/clearBrowserData').Keys("[Enter]"); // hit Enter in clear browser data dialog
    browser.Page('chrome://settings/').Close(); // close settings page after clearing browsing data


  • ucuber's avatar
    Occasional Contributor

    Aside the fact, that the question is a little bit older, here a solution in python for chrome I made for my tests. If you have some ideas to make it more elegant or effective or if you see errors, feel free to refactor it


    Remark: on my system all the chrome stuff is in Roaming, so I use AppData instead of LocalAppData


    def clear_stored_info_chrome():
        excluded_items = [item.upper() for item in [
                              r"Origin Bound",
        found_items = [item.upper() for item in glob.glob(
                            r"Google\Chrome\User Data\Default\*"
        for item in found_items:
          is_excluded = [True for tag in excluded_items if tag in item]
          if not is_excluded:
              if os.path.isdir(item):
                 shutil.rmtree(item, ignore_errors=True)
            except BaseException as e: # I ignore errors of any kind, just a remark to Log
              Log.Message("clear chrome stored info: {} - {}".format(item, e))