I'm struggling with setting "document.cookie" value via Selenium. I want to achieve something like this. Generally, when I'm on a real browser like Chrome, I open the console and type
document.cookie='my_secret_cookie=1;path=/'
And everything works like a charm.
How can I achieve this via Selenium? Currently, I've done something like this, but it doesn't seem to work for me:
Date today = new Date();
Date tomorrow = new Date(today.getTime() + (1000 * 60 * 60 * 24));
Cookie newCookie = new Cookie.Builder("myCookie","my_secret_cookie=1")
.domain("my.site") // declared in my local.properties file
.path("/")
.expiresOn(tomorrow)
.isSecure(true)
.build();
driver.manage().addCookie(newCookie);
Any advice?