- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to send cookies with selenium webdriver?
We can send cookies with Selenium webdriver. A cookie is stored in a key value pair. First, we have to add cookies, then can delete them. We can also get the cookies.
Also, we have to add import org.openqa.selenium.Cookie statement for cookie implementations.
Syntax
Cookie ck = new Cookie("Automation", "QA"); driver.manage().addCookie(ck); driver.manage().getCookies(); driver.manage().deleteAllCookies();
Example
Code Implementation
import java.util.Set; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.Cookie; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class CookiesSend{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS); driver.get("https://www.tutorialspoint.com/index.htm"); // cookie set with name and value Cookie ck = new Cookie("Automation", "QA"); // cookie newly added driver.manage().addCookie(ck); // get all cookies Set<Cookie> cks = driver.manage().getCookies(); //iterate the cookies for (Cookie cook : ck) { System.out.println("Cookie name is: "+ cook.getName()); System.out.println("Cookie Value is : "+ cook.getValue()); } // delete all driver.manage().deleteAllCookies(); // get cookies Set chs = driver.manage().getCookies(); System.out.println("Cookie count after delete: "+chs.size()); driver.quit(); } }
Output
- Related Articles
- Clear browser Cookies with Selenium WebDriver Java bindings.
- How to save and load cookies using Python Selenium WebDriver?
- How to send a report through email using Selenium Webdriver?
- Delete Cookies On All Domains using Selenium Webdriver.
- Send keys without specifying element in Python Selenium webdriver
- How to work with cookies in Selenium with python?
- How to send keyboard input to a textbox on a webpage using Python Selenium webdriver?
- How to take screenshot with Selenium WebDriver?
- How install Selenium Webdriver with Python?
- How to deal with ModalDialog using selenium webdriver?
- How to launch Edge browser with Selenium Webdriver?
- How to take partial screenshot (frame) with Selenium WebDriver?
- How to scroll down using Selenium WebDriver with Java?
- How to get Response Status Code with Selenium WebDriver?
- How to interact with hidden elements in Selenium Webdriver?

Advertisements