What is Browser Cache
Whenever we browse a website, the information on the websites is cached in a temporary storage location on our computer for files downloaded by our browser to reduce the page loading time next time the website is browsed. The file includes HTML pages, images, CSS style sheets, and JavaScript scripts.
What is Browser Cookie
A cookie is a small piece of information that is sent by the webserver to your browser when you visit a website. The browser stores these pieces of information in a small file called Cookie.txt.Cookies were designed to remember various information like items added in the shopping cart in an online store or to record the user’s browsing activity. Cookies are also be used to remember the user’s data previously entered into form fields such as usernames, passwords, email id, addresses, and credit card numbers, etc.
Delete browser Cookies in UFT using WebUtil
We can use the DeleteCookies method available under the WebUtil class to delete cookies for the IE browser.
Write the following code to delete all cookies for IE browser.
Webutil.DeleteCookies
Delete Cookies for a Domain on IE Browser
We can use DeleteCookies method on a browser object to delete all cookies of the browser.
Syntax
object.DeleteCookies [FromSource]
Parameter | Description |
FromSource | Optional. A String value. The full or partial domain of the source. For example, entering MySite.com or MySite.net clears cookies only from the specified site, and entering MySite clears cookies from all related domains. Default value = “” |
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
Browser("Shop1234").Navigate "www.myShop1234.com/" Browser("Shop1234").Page("Shop1234").WebEdit("Search-keywords").Set "UFT" Browser("Shop1234").Page("Shop1234 UFT").Link("UFT").Click Browser("Shop1234").Page("Shop1234 UFT").Image("Add to Shopping Cart").Click Browser("Shop1234").Page("Shop123 Shopping Cart").Image("Add to cart").Click 'Delete cookies from the shopping site domain Browser("Shop1234").DeleteCookies "MyShop1234" 'Refresh the browser Browser("Shop1234").Refresh |
Clear Cache from the browser in UFT
To clear cache from the browser use the following code.
1 |
Browser("Shop1234").ClearCache |
Clear IE Cache, Cookie & History Using VBA/Shell Scripting
Use the following code for the following purposes.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Set WshShell = CreateObject("WScript.Shell") WshShell.run "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1" 'Clear History WshShell.run "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2" 'Clear Cookie WshShell.run "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8" 'Temp files WshShell.run "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16" 'Clear form data WshShell.run "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32" 'Clear Save passwords WshShell.run "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255" 'Clear All |
Delete History From Chrome and Mozilla Firefox
The above-discussed method will not work for a web browser other than IE. To clear history from other browsers use the following workaround.
Use keyboard shortcut Ctrl + Shift + Delete to invoke the Clear History/Browsing dialog box. Once the dialog box is displayed, write the automation code to delete whatever data you want.
Use the following code to invoke the History/Browsing dialog box.
1 2 3 4 5 |
Browser("Welcome: Mercury Tours").Highlight 'Make sure the browser is in the foreground Set WshShell = CreateObject("WScript.Shell") WshShell.SendKeys "^+{DELETE}" 'Sending Ctrl, Shift and Delete Key together |
Recommended Posts
- How To Add Checkpoints in UFT
- Discussing Bitmap Checkpoint In-Depth UFT
- How to Use Test Combinations Generator in UFT
- How to Install WPF Add-in in UFT
- Read Excel Using ADODB Connection in UFT | VBA
- Read, Write and Update Excel File In UFT
- How To Use Dictionary Object in UFT With Examples
- How to Use Shell Scripting in UFT to SendKeys
- File System Object UFT | VBA