• Posted by Intent Media 12 Feb

Deleting Cookies in Safari 6.0 with Selenium WebDriver

One of the many useful features of Selenium WebDriver is that it can act as a wrapper for several different browser drivers. This means (in theory, at least) that if you restrict yourself to calling methods exposed by the WebDriver API, you can reuse the same code to drive automated tests in any of the browsers WebDriver supports.

In practice, however, this is not always the case. There can be subtle differences in how WebDriver’s methods are implemented for each browser. In some cases, certain browsers may not support a given method at all.

One example is deleting cookies. In Ruby, we can tell WebDriver to delete all cookies for the current domain via a call to


This executes WebDriver’s browser-specific implementation of the delete_all_cookies method, which for most browsers works as expected.

For Safari, a message is passed to the SafariDriver telling it to execute its own cookie deletion method. In OSX, SafariDriver does this by deleting theĀ ~/Library/Cookies/Cookies.binarycookies file where the cookie data is stored.

Unfortunately, as of Safari 6.0, cookie data is also stored in active memory by the cookied process. If cookied notices that Cookies.binarycookies is missing, it simply recreates the file from memory — so deleting it is no longer enough. SafariDriver has not yet been updated to reflect this change.

Fortunately, there is a simple workaround: after deleting the cookie jar, just kill cookied! In Ruby we can accomplish this by calling out to the shell with

%x( rm ~/Library/Cookies/Cookies.binarycookies )
%x( killall cookied )

We don’t have to worry about this breaking Safari’s cookie management — if Safari notices that cookied isn’t running (whenever it looks for some cookie, for example) it restarts the process.

Happy testing,

Amasa Amos
Quality Assurance Engineer

Post Comments 1

Posted by parasmal patidar on
  • Jun 2 2015
But how to do it on remote machine, how to execute shell command on remote machine... -Paras