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.
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.
- You need to write a custom function to do this. IMHO there is no direct way available.
- Write a shell script to reach to the cookies file residing in your corresponding folder.
- 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
To delete Cookies from the browser
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
There are interesting methods posted in the comments section below, don’t forget to check those.