Add a Cookie

To add a cookie using Selenium for Java, call manage().addCookie() on the WebDriver object and pass the Cookie object as argument to the addCookie() method.

The following is a simple code snippet to add a cookie named "dummy" with value "xyz123".

</>
Copy
driver.manage().addCookie(new Cookie("dummy", "xyz123"));

where driver is a WebDriver object. Cookie() constructor can take the key and value as arguments to create a cookie object.

This method call returns void.

Example

In the following program, we write Selenium Java code to visit Wikipedia Home Page, and add the Cookie with key-value pair (“dummy”, “xyz123”).

Java Program

</>
Copy
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;

public class MyAppTest {
	public static void main(String[] args) {
		System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver");
		WebDriver driver = new ChromeDriver();
		
		try {
			driver.get("https://en.wikipedia.org/wiki/Main_Page");
			driver.manage().addCookie(new Cookie("dummy", "xyz123"));
			System.out.println("Cookies : \n" + driver.manage().getCookies());
		} finally {
			driver.quit();
		}
	}
}

Output

Cookies : 
[dummy=xyz123; path=/; domain=en.wikipedia.org;secure;, GeoIP=IN:TG:Hyderabad:17.43:78.51:v4; path=/; domain=.wikipedia.org;secure;, WMF-Last-Access-Global=26-Jun-2022; expires=Thu, 28 Jul 2022 09:30:20 IST; path=/; domain=.wikipedia.org;secure;, WMF-Last-Access=26-Jun-2022; expires=Thu, 28 Jul 2022 09:30:20 IST; path=/; domain=en.wikipedia.org;secure;]

Screenshot

Add a Cookie - Selenium Java

As you may notice, other values in the cookie like path and domain are set to default values for the cookie.

https://tigaprediksi.com/

https://armynavysuperstores.com/

https://dutawarta.com/

https://woaynews.com/

https://pupwb.org/

https://haraznews.com/

https://girimenangnews.com/

https://geprekbensuindonesia.com/

https://everythinginclick.com/wp-content/uploads/slot-bonus/

https://caraslot.com/wp-includes/slot-bonus/

https://www.casablancahire.com/blogs/wp-includes/slot-bonus/

https://www.genesiscalbeautystudio.com/wp-includes/slot-bonus/

https://www.hookdonthehudson.com/

https://bimbelruangprestasi.com/wp-includes/slot-bonus/

https://thenews100.com/

https://expertautokool.ee/wp-includes/slot-bonus/

https://www.padslakecounty.org/wp-content/uploads/rekomendasi-situs-slot-gacor-gampang-menang/

https://www.wlvliquors.com/wp-includes/slot-gacor/

https://rapbooster.com/wp-includes/slot-bonus/

https://ganit-prag.com/wp-includes/slot-bonus/

https://rakyatjelata.com/wp-includes/slot-gacor/

https://rakyatjelata.com/wp-includes/slot-bonus

https://www.luxurytrees.com/wp-includes/slot-bonus/

https://hastshilpchennai.com/wp-includes/slot-nexus/

slot bonus new member

slot bonus new member

https://www.zdravei.org/wp-includes/situs-slot-gacor/