[英]How to get cookies on internet explorer using Selenium webdriver - C#
I need to run my test scripts on IE11. 我需要在IE11上运行测试脚本。 I am using c#.
我正在使用c#。
Part of my script makes an API call using cookies on the current page. 我的脚本的一部分使用当前页面上的cookie进行了API调用。
I have this in my code: 我的代码中有这个:
IReadOnlyList<Cookie> cookies = _driver.Manage().Cookies.AllCookies;
to get cookies from current page. 从当前页面获取Cookie。 It works well for Chrome, Firefox but for IE11 it always returns 0. however, there are cookies on the page.
它适用于Chrome,Firefox和IE11,但始终返回0。但是,页面上有Cookie。
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; 您可以使用JavaScript获取所有cookie。
object cookies = ((IJavaScriptExecutor)_driver).ExecuteScript("return document.cookie");
Edit: 编辑:
32-Bit Web Driver for Internet Explorer is working fine for cookies. Internet Explorer的32位 Web驱动程序可以很好地处理Cookie。
However it is not working with 64-Bit . 但是,它不适用于64位 。
You can use the latest version which you can download it from here ; 您可以使用最新版本,也可以从此处下载最新版本;
IEDriverServer_Win32_3.141.5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.