Micro Focus QTP (UFT) Forums
Disable cookies in IE8? - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Disable cookies in IE8? (/Thread-Disable-cookies-in-IE8)



Disable cookies in IE8? - ngocvo3103 - 01-18-2011

Hi guys,

I'm trying to disable cookies in IE8 using QTP 10.
The manual way is:
- Go to Tools/Developer Tools
- In Developer Tools window, choose Cache/Disable Cookies

When capturing interface for the tool bar, I got it as WinToolbar. Search for the methods of this object i found only 2 methods to use:
- Object.Press "Tools" and Object.Type "Tools"

I tried using this way
1. Object.Press "Tools"
2. Object.Type "{F12}"
It works for me but not stable. I would like to have a stable solution for this situation.

Rightnow, I'm using the sendkey method which is quite stable for me, but this solution is still not stable. This is my code:
Code:
Set WshShell = CreateObject("WScript.Shell")
        While Window("Developer Tools").Exist(2) = False
            Browser("micclass:=Browser").Page("micclass:=Page").SetTOProperty "focus", True
            WshShell.AppActivate "Internet Explorer"
            WshShell.SendKeys("{F12}")
            Wait(2)    
        Wend

        WshShell.AppActivate "Developer Tools"
        WshShell.SendKeys("%c")
        Wait(2)
        WshShell.SendKeys("c")
        Wait(2)
        WshShell.SendKeys("{F12}")
Thankful for any solution.

Ngoc Vo


RE: Disable cookies in IE8? - cdesserich - 01-20-2011

The most reliable way I know would be to edit the registry settings. Here's some subroutines that will disable/enable cookies (you have to call the sub, then open the browser, or restart the browser after calling it). Instead of just calling the enable sub, you might want to read the registry setting before altering it (ShellObj.RegRead) so that you can set it back where it was. Setting it to 0 will allow ALL cookies. Refer to this for more info on the registry settings for IE and what they mean: http://support.microsoft.com/kb/182569

Code:
'@Description Disables cookies in Internet Explorer for the current user. Browser(s) must be restarted for this to take effect!
Public Sub DisableCookies()
    Set ShellObj = CreateObject("WScript.Shell")
    ShellObj.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\1A10", 3, "REG_DWORD"
    Set ShellObj = Nothing
End Sub

'@Description Enables cookies in Internet Explorer for the current user. Browser(s) must be restarted for this to take effect!
Public Sub EnableCokies()
    Set ShellObj = CreateObject("WScript.Shell")
    ShellObj.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\1A10", 0, "REG_DWORD"
    Set ShellObj = Nothing
End Sub