简体   繁体   English

如何使用Selenium Webdriver在Internet Explorer上获取Cookie-C#

[英]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.

相关问题 C#Selenium Webdriver在Internet Explorer中捕获javascript错误 - C# Selenium webdriver Catch javascript errors in Internet explorer C#WebDriver Internet Explorer,如何在静默模式下执行? - C# WebDriver Internet Explorer, How to execute in silent mode? C#WebDriver Internet Explorer安全提示 - C# WebDriver Internet Explorer Security Prompts 使用Selenium C#进行Internet Explorer自动化测试 - Internet Explorer automated testing using Selenium C# 如何使Selenium Webdriver集中精力(使用C#)? - How do I get Selenium Webdriver to focus (using c#)? 如何在 C# 中使用 Selenium WebDriver 获取当前窗口的 URL? - How to get the URL of the current window using Selenium WebDriver in C#? 如何使用Selenium Webdriver(C#)获取页面名称? - How to get a page name using Selenium Webdriver (C#)? 在 selenium webdriver C# 中为 chrome 设置 cookies - Setting cookies in selenium webdriver C# for chrome 如何使用C#中的AutoIT库在具有硒驱动程序的Internet Explorer中下载文件? - How to Download file in Internet Explorer with selenium driver using AutoIT library in C#? 使用 Selenium Webdriver 时,使用 InternetExplorerDriver 时出现以下错误 - “启动 Internet Explorer 时出现意外错误...” - When using Selenium Webdriver, I get the following error using the InternetExplorerDriver - “Unexpected error launching Internet Explorer…”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM