The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →To clear cookies with Selenium, navigate to the relevant site and call driver.delete_all_cookies(); to remove one cookie, use driver.delete_cookie("name"). In PhantomJS, page.deleteCookie("name") removes a matching cookie visible to the current URL, while phantom.cookies exposes the broader cookie jar. These commands do not clear every kind of browser state, and PhantomJS’s cookie-file settings can make cookies appear again on a later run.
First clarify what “clear sessions” means
In browser automation, “session” can mean several different things: a cookie used for authentication, all cookies available to the current site, a WebDriver session, browser storage, or the server-side login session. Cookie deletion addresses only cookies. It does not by itself clear local storage, session storage, cached resources, or a session maintained on the server.
Choose the operation that matches the state you want to remove:
- One named cookie: delete that cookie in the current site context.
- All cookies Selenium can delete in the current context: navigate to the site, then use the binding’s delete-all-cookies command.
- A cookie visible to the current PhantomJS page: call
page.deleteCookie(name). - PhantomJS cookies across domains or carried between runs: inspect its global cookie jar and any configured cookie file.
- A complete fresh browser profile: use an appropriately isolated profile or browser context; cookie deletion alone is not a complete reset.
Deleting a browser cookie also does not necessarily invalidate a session on the server. If the application keeps a server-side session alive, use its logout or session-revocation mechanism when that is the goal.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11#1 Best Overall
Clear cookies with Selenium in Python
Delete all cookies in the current browsing context
With Selenium Python, call delete_all_cookies() after navigating to the relevant origin. Cookie operations are associated with the active document in the current browsing context; this is not a command to erase every domain’s data from the browser profile.
from selenium import webdriver
driver = webdriver.Chrome()
try:
driver.get("https://example.com")
driver.delete_all_cookies()
finally:
driver.quit()
Remove the accidental leading space before driver if copying this snippet into a file: Python requires the top-level assignment to begin at the left margin. Here is the correctly formatted runnable version:
from selenium import webdriver
driver = webdriver.Chrome()
try:
driver.get("https://example.com") # Be on the relevant origin/context.
driver.delete_all_cookies()
finally:
driver.quit()
The try/finally ensures the browser is quit even if navigation or cookie deletion raises an exception. Replace the example URL with the site whose cookies you intend to manipulate.
Delete only one cookie
Use Selenium Python’s named-cookie method when you want to preserve other cookies:
Rank #2
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
driver.get("https://example.com")
driver.delete_cookie("session")
The supplied name must match the cookie’s name. If the cookie is not available in the current context, inspect the cookies Selenium can see before attempting deletion:
for cookie in driver.get_cookies():
print(cookie["name"], cookie.get("domain"), cookie.get("path"))
This can help distinguish a misspelled name from a cookie that belongs to another domain or path. Selenium bindings in other languages provide corresponding cookie-deletion operations; check the API for the binding and version your project actually uses.
Delete cookies with PhantomJS
PhantomJS provides its own webpage API. page.deleteCookie(cookieName) removes matching cookies visible to the page’s current URL and returns a boolean: true if a matching cookie was successfully deleted, otherwise false.
var webpage = require('webpage');
var page = webpage.create();
page.open('https://example.com', function (status) {
if (status !== 'success') {
console.error('Could not open the page');
phantom.exit(1);
return;
}
var deleted = page.deleteCookie('session');
console.log('Cookie deleted:', deleted);
phantom.exit();
});
Use the actual cookie name in place of session. The call is scoped to cookies visible to the current URL, so it is not equivalent to erasing all cookies for every domain. The boolean result is useful as an immediate check, but it does not establish that local storage or server-side login state has been cleared.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Rank #3
Inspect PhantomJS’s broader cookie jar
PhantomJS also exposes phantom.cookies, an array of cookies across domains. That is a different scope from a page-level deletion. When an automation run appears to restore old cookies, inspect the global jar and the startup configuration rather than repeatedly deleting only the current page’s visible cookie.
PhantomJS can initialize cookie data from a cookie file specified through startup configuration or command-line options. If such a file is in use, check whether the run loads it again and whether the script or surrounding process writes updated data back. Otherwise, deleting a page-visible cookie during one run may not prevent the next run from loading persisted cookie data.
What cookie deletion does—and does not—reset
Cookies versus browser storage
Cookies are only one layer of website state. If a site still behaves as though it remembers a user after cookie deletion, check for other state mechanisms separately:
- Local storage: persistent key-value data associated with a site.
- Session storage: per-tab or per-window state that is separate from cookies.
- Cache: saved network resources, which are not authentication cookies.
- Server-side session: application state that may remain valid until logout, expiry, or revocation.
Use the browser’s appropriate storage APIs or a clean browser profile when your test requires these layers to be reset. Do not interpret a successful cookie deletion as proof that all browser or application state is gone.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Rank #4
- Brand: Wiley
- Set of 2 Volumes
- A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
WebDriver session versus website login session
Calling driver.quit() ends the WebDriver-controlled browser session and releases its browser resources. It is not a substitute for explicitly deleting cookies when you need to test a particular cookie operation, nor does it prove that a server-side login token has been revoked. Similarly, restarting a browser does not guarantee a fresh state if the automation uses a persistent profile or reloads cookie data.
Choose the right method
| Need | Use | Scope and caution |
|---|---|---|
| Delete one Selenium cookie | driver.delete_cookie("name") |
Current WebDriver context; navigate to the relevant site first. |
| Delete all Selenium cookies | driver.delete_all_cookies() |
Current browsing context, not all browser profile data or every domain’s stored state. |
| Delete one PhantomJS cookie | page.deleteCookie("name") |
Matching cookie visible to current URL; returns true or false. |
| Investigate PhantomJS cross-domain or persistent cookies | Inspect phantom.cookies and cookie-file startup settings |
Global cookie jar and configured persistence may be involved. |
Troubleshoot cookies that remain or return
The cookie was not deleted
- Check the current URL. Navigate to the relevant site before calling Selenium’s cookie methods or PhantomJS’s page-level deletion.
- Confirm the exact name. Enumerate cookies visible to Selenium with
get_cookies(); cookie names are not interchangeable with values. - Check domain and path context. A cookie associated with a different host or URL context may not be visible to the current page operation.
- Check the PhantomJS return value. A
falseresult means the matching visible cookie was not successfully deleted by that call.
The cookie returns after restarting
- Look for a PhantomJS cookie file configured in startup settings or command-line options.
- Check whether the automation launches with a persistent browser profile rather than a fresh one.
- Determine whether application code or a subsequent navigation sets the cookie again.
Distinguish a cookie that was never removed from one that was removed and then recreated. Inspect the cookie list immediately after deletion and again after the next navigation or restart.
The site still shows the user as logged in
Cookie deletion alone does not clear local storage, session storage, or server-side state. Inspect those separately, and use the application’s logout or token-revocation flow if you need to end the server session. For reliable repeatable tests, define which state layers must be reset and create an isolated context or profile accordingly.
PhantomJS does not work with the Selenium version in use
PhantomJS documentation describes its embedded Remote WebDriver mode and Selenium Grid configuration, but that documentation does not establish compatibility with current Selenium releases. Treat PhantomJS integration as a legacy-environment decision: verify the exact PhantomJS, Selenium, driver, and Grid versions used by your project before relying on it. Do not assume that instructions written for PhantomJS 2.1.1 apply to a current Selenium installation.
Free tools Windows power users keep installed
One-click scans. No signup required.
Best Value
Or skip the browser setup
If the task is capturing a page rather than testing or deleting its session cookies, ScreenshotNeo can return a screenshot or PDF from one API request. It does not clear a browser session; use Selenium or PhantomJS above when cookie deletion is the actual requirement. The API accepts URL-based capture options, and its documentation is at ScreenshotNeo’s API docs.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
For a capture, ScreenshotNeo removes cookie/consent banners, newsletter popups, and chat widgets before the shot; those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers report the page verdict and billing status. Its MCP server includes tools for AI agents to take screenshots and capture PDFs. The free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots. Sign up for free: 1,000 screenshots a month, no card required.
Frequently Asked Questions
Does deleting cookies end my account session on the website?
Not necessarily. It removes browser cookies in the relevant scope, but the site may maintain server-side state or use another storage mechanism.
Does PhantomJS’s deleteCookie method delete every cookie?
No. It targets matching cookies visible to the current URL. PhantomJS’s broader cookie jar and any configured cookie file are separate considerations.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

