The following action removes cookie with a given name, belonging to a given path:

// The following examples try to give an indication of how Selenium can be extended with javascript.
function createCookie(doc, name,value, path,days)
        if (!path) {
            path = "/";        
        if (days)
                var date = new Date();
                var expires = "; expires="+date.toGMTString();
        else var expires = "";
        doc.cookie = name+"="+value+expires+"; path="+path;

 * Removes the cookie with the given name.
 *  text - the cookie name
 *  path - the cookie path
Selenium.prototype.doRemoveCookie = function(text, path) {    
    createCookie(, text, "", path, -1);

I found the code for the createCookie on the Selenium forums. I just added a member function on the Selenium object prototype named doRemoveCookie which in effect creates a Selenium action 'removeCookie'.


removeCookie JSESSIONID /admin
removeCookie JSESSIONID /

In the example above, I call the removeCookie twice, one removing a JSESSIONID cookie set on the root (/) and one removing a JSESSIONID cookie set on the directory /admin. In some cases, I found that it would be relevant to have to give the path information as some servers set cookies with the same name on different paths.


  • For more information about usage, visit my hompepage and my blog.


Plain text icon removeCookie.txt782 bytes