Skip to content
TheChatArchiveThe Chat Archive
gpt-4.1-2025-04-14· OpenAIHugging Face LMArena Human Preference 140K

Using selenium for python, how do we clear cookies for a website ?

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-sonnet-4-20250514’s answer.
  1. User

    Using selenium for python, how do we clear cookies for a website ?

  2. Assistant

    To clear cookies for a website using Selenium in Python, you can use the delete_all_cookies() method provided by the Selenium WebDriver. This method deletes all cookies for the current domain.

    Here's a simple example:

    from selenium import webdriver
    
    # Initialize the WebDriver (e.g., Chrome)
    driver = webdriver.Chrome()
    
    # Open the website
    driver.get('https://example.com')
    
    # Clear all cookies for the current domain
    driver.delete_all_cookies()
    
    # (Optional) Refresh the page to see the effect
    driver.refresh()
    
    # Continue with your automation...
    

    Notes:

    • delete_all_cookies() only removes cookies for the current domain loaded in the browser.
    • If you want to clear cookies for multiple domains, you need to navigate to each domain and call delete_all_cookies() for each one.

    If you want to delete a specific cookie:

    driver.delete_cookie('cookie_name')
    

    If you want to get all cookies:

    cookies = driver.get_cookies()
    print(cookies)
    

    Summary:

    • Use driver.delete_all_cookies() to clear all cookies for the current website.
    • Make sure the driver is on the domain you want to clear cookies for.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.