How to clear cookies in Firefox ?

There is no straightforward way to clear cookies in Firefox through QTP. Using sendkeys to simulate how we do it manually seemed ridiculously out of the question, so I came up with the following code after doing some research :-


Set FSO = CreateObject(“Scripting.FileSystemObject”)

Dim oShell
Set oShell = CreateObject(“WScript.Shell”)

Dim sUserProf
sUserProf = oShell.ExpandEnvironmentStrings(“%USERPROFILE%”) & “\AppData\Roaming\Mozilla\Firefox\Profiles”

If FSO.FolderExists(sUserProf) Then
Set oFolder = FSO.GetFolder(sUserProf)
If oFolder.SubFolders.Count> 0 Then

‘oFolder.item(0) throws an error, so we use a workaround to find the first folder
For each oFolder in oFolder.SubFolders
Exit For

Dim sPath
sPath = oFolder.Path

For each afile in FSO.GetFolder(sPath).Files
extension= fso.GetExtensionName(afile)

On Error Resume Next
If Instr(extension,”sqlite”)>0 and Instr(,”cookies”)>0 Then
End If
On Error Goto 0


End If
End If


Please note that firefox should be closed in order for this code to execute. This code can also be written in a plain vbs file and executed directly without QTP.


Happy Automating !

Harshit Kohli


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s