Monday, May 2, 2011

Cookies

How to get all cookies for the current domain:

puts $ie.document.cookie

How to get value of a specific cookie:

$carray = $ie.document.cookie.split(';')
$carray.length.times do |i|   
    if /MyCookie/.match($carray[i])
       $cookieval = $carray[i]
       $cvalarray = $cookieval.split('=')
       $cookieval = $cvalarray[1]     
    end 
end
puts $cookieval

How to delete all cookies:

require "fileutils" 
cookieDir = "C:\\Documents and Settings\\#{ENV['USERNAME']}\\Cookies"
FileUtils.rm_rf cookieDir

NOTE! These examples only work for IE!

Check e.g. from here how to manage cookies in Firefox ...

No comments:

Post a Comment