Dilip Agheda
Dilip Agheda

Reputation: 2547

How to get cookies on internet explorer using Selenium webdriver - C#

I need to run my test scripts on IE11. I am using c#.

Part of my script makes an API call using cookies on the current page.

I have this in my code:

IReadOnlyList<Cookie> cookies = _driver.Manage().Cookies.AllCookies;

to get cookies from current page. It works well for Chrome, Firefox but for IE11 it always returns 0. however, there are cookies on the page.

Upvotes: 1

Views: 1999

Answers (1)

Recep Duman
Recep Duman

Reputation: 123

There are too many open issues about this. But none of them is closed with the solution. After several times I tried I decided to go with a workaround.

You can use JavaScript to get all cookies;

object cookies = ((IJavaScriptExecutor)_driver).ExecuteScript("return document.cookie");

Edit:

32-Bit Web Driver for Internet Explorer is working fine for cookies.
However it is not working with 64-Bit.

You can use the latest version which you can download it from here;

IEDriverServer_Win32_3.141.5

Upvotes: 2

Related Questions