Page 1 of 1

How to get cookies from Browser

Posted: Mon Jan 07, 2019 8:36 pm
by jarrettmk
Our web application sets a cookie that I need to retrieve and decrypt in order to get some information needed to validate later in my test.

I have looked at Host.Current as well as the following to try and get the cookies with no luck...
var cookies = Repository.OURSITE.Self.ExecuteScript("document.cookie");
and
var cookies = Repository.OURSITE.Self.ExecuteScript("document.cookie.split(';');");
both return "undefined".

I know with straight Selenium you can use something like:
var cookies = remoteWebDriver.Manage().Cookies;
or
var cookies = driver.Manage().Cookies;
However, I cannot find anything like this that is equivalent in Ranorex.

Does anyone know how to get the browser's cookies?

Re: How to get cookies from Browser

Posted: Tue Jan 08, 2019 9:10 am
by RobinHood42
Hi,

Please try the following code:
var cookies = Repository.OURSITE.Self.ExecuteScript("return JSON.stringify(document.cookie)");
Cheers,
Robin

Re: How to get cookies from Browser

Posted: Tue Jan 08, 2019 6:22 pm
by jarrettmk
That did the trick. Thanks!

Re: How to get cookies from Browser

Posted: Tue Mar 16, 2021 6:03 pm
by jarrettmk
The previously posted solution worked for me up until the latest build our developers sent over. They said that they have changed the cookies so that now they cannot be accessed via JavaScript so the above mentioned solution is now breaking. Is there another way to grab cookies from the browser without using JS?

Re: How to get cookies from Browser

Posted: Tue Jan 30, 2024 11:05 pm
by riagarwal
Hello Team,

Any help on this is required. I am not able to get the cookies tried using all the methods from the forum.

var cookies = repo.iDoxs.UserConsole.PROD.Self.ExecuteScript("document.cookie;");
var cookies2 = repo.iDoxs.UserConsole.PROD.Self.ExecuteScript("return document.cookie;");
var cookies3 = repo.iDoxs.UserConsole.PROD.Self.ExecuteScript("return JSON.stringify(document.cookie);");

Any help is appreciated.

Re: How to get cookies from Browser

Posted: Thu Feb 22, 2024 11:49 am
by Marie143
jarrettmk wrote:
Tue Jan 08, 2019 6:22 pm
That did the trick. Thanks!Fort Worth Drywall Solutions
How?