Selenium WebDriver 4

Add and delete a cookie

Medium70 pts~25 min
  • Cookies
  • Browser state
Practice app · Document Vault

File upload and download, cookies, localStorage, sessionStorage and JavaScript execution.

Test URL
/lab/selenium-add-and-delete-a-cookie

Your starter code already declares TEST_URL — never hardcode a host.

Objective

Manage cookies directly from the driver: add a new cookie and delete the app's session cookie.

Your task

  1. 1Click #set-cookie so session_id=abc123 exists.
  2. 2Add a cookie named promo_code with value SAVE10 through the driver.
  3. 3Wait until #cookie-value contains “promo_code=SAVE10” (the page re-reads cookies every 0.5 s).
  4. 4Delete the session_id cookie and assert the driver no longer returns it.

Acceptance criteria

  • A cookie is added and another deleted through the driver
  • #cookie-value contains promo_code=SAVE10
  • At least 2 assertions pass

Selenium WebDriver 4 · Selenium · Files, windows & storage