Handling session cookies

Websites use cookies to store user preferences, login information, and various other details of the client. The Selenium WebDriver API provides various methods to manage these cookies during testing. Using these methods, we can read cookie values, add cookies, and delete cookies during the test. This can be used to test how the application reacts when cookies are manipulated. The WebDriver.Options interface provides the following methods to manage cookies:

Method

Description

addCookie(Cookie cookie)

This method adds a cookie.

getCookieNamed(String name)

This method returns the cookie with a specified name.

getCookies()

This method returns all the cookies for current domain.

deleteCookieNamed(String name) ...

Get Selenium Testing Tools Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.