Cookies are those small files on your computer that store information between sessions or between two login attempts. There are valid reasons where you might need to delete cookies stored on your computer through scripting.Delete cookies

Now, how can we delete cookies through VB Scripting in QTP? This one is a very often repeated question on the testing tools forums. I will first provide a hint here.

  1. You need to write a custom function to do this. IMHO there is no direct way available.
  2. Write a shell script to reach to the cookies file residing in your corresponding folder.
  3. Delete all the files inside that folder.

Please post your script in the comments below. If I don’t get an answer by tomorrow, I will update the post with my script.

Answer: Use WebUtil.DeleteCookies whenever you want to delete cookies from IE.

Update: As pointed by Paul on LearnQTP feedback forum, we now have some other methods as well to delete cookies/browser cache.

To clear Cache from the browser

Browser("Page Title").ClearCache

To delete Cookies from the browser

Browser("Google.com:").DeleteCookies "Google"

The above code will delete cookies for ALL Google domains like google.net, google.com, google.in.  If you wish to remove cookies for a specific domain use the corresponding Top Level Domain

Browser("Google.com:").DeleteCookies "Google.in"

There are interesting methods posted in the comments section below, don’t forget to check those.

Welcome new readers: Download the Free eBook!

I am Ankur Jain, the owner of LearnQTP and founder of a software organization. This site is run, maintained and updated by me and my team. Feel free to take a look around, you may want to start with What is QTP? 

You can connect with me on twitter @ajonit. 

Please enter your first name and email address below to instantly download the eBook on Optimizing QTP Scripts. In future, we will make sure you get new tips & tricks on QTP delivered direct to your email box.

You have Successfully Subscribed!

Share This