Skip to main content

deleteCookies

Overview

Use the deleteCookies command to delete all or specific cookies for the current page.

To delete specific cookies, you need to specify the cookie name as a string or a list of cookie names as an array of strings.

Usage

await browser.deleteCookies(names);

Command Parameters

NameTypeDescription
namesString or String[]Optional parameter. The cookie name or list of cookie names to delete. If the parameter is missing, all cookies for the current page will be deleted.

Usage Examples

it("should delete cookies", async ({ browser }) => {
await browser.setCookies([
{ name: "test", value: "123" },
{ name: "test2", value: "456" },
{ name: "test3", value: "789" },
]);

let cookies = await browser.getCookies();
console.log(cookies);
// outputs:
// [
// { name: 'test', value: '123' },
// { name: 'test2', value: '456' },
// { name: 'test3', value: '789' }
// ]

await browser.deleteCookies(["test3"]);

cookies = await browser.getCookies();
console.log(cookies);
// outputs:
// [
// { name: 'test', value: '123' },
// { name: 'test2', value: '456' }
// ]

await browser.deleteCookies();
cookies = await browser.getCookies();
console.log(cookies); // outputs: []
});

References

We'd like to give credit to the original WebdriverIO docs article, from which we drew some information while writing our version.