Is it possible to launch url with specific cookie? | Selenium Forum
M
Posted on 21/11/2015
I wanted to hit user with specific cookie. The reason is my application server has located n multiple places.Ex Hyd,Mumbai, Delhi. Now any user hit that site response should go to from nearest server. Now each server has unique cookie.Based on that cookie we came to that server details.
Now this i have to achieve through selenium. Done all the required things. Like below.
1. Launched URL
2. Add respective cookie using addcookie commands
3. Refresh the browser, By dong that request will sent to the server and will get respond from the respective server.
Every thing working fine.

Now my question is it possible to launch url with specific cookie?

M
Replied on 23/11/2015

so, you want to add a cookie?


it can be done by



public void addCookie()
{
driver= new FirefoxDriver();
String URL="http://flipkart.com/";
driver.navigate().to(URL);
//we should pass name and value for cookie as parameters
// In this example we are passing, name=mycookie and value=123456789123
Cookie name = new Cookie("mycookie", "123456789123");
driver.manage().addCookie(name);

// After adding the cookie we will check that by displaying all the cookies.
Set<Cookie> cookiesList = driver.manage().getCookies();
for(Cookie getcookies :cookiesList) {
System.out.println(getcookies );
}
}