C# Selenium/ChromeDriver Add User Profile Preference(C# Selenium/ChromeDriver 添加用户配置文件首选项)
问题描述
在使用 selenium + chrome 驱动程序运行测试时,我需要允许所有 cookie.
I need to allow all cookies when running tests with selenium + chrome driver.
我正在尝试使用 将此添加为配置文件首选项ChromeOptions.AddUserProfilePreference
我不能 100% 确定允许所有 cookie 的首选项名称应该是什么.我已经引用了这个文档 https:///src.chromium.org/viewvc/chrome/trunk/src/chrome/common/pref_names.cc?view=markup
I'm not 100% sure what the preference name should be to allow all cookies. I have referenced this doc https://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/pref_names.cc?view=markup
并在我的设置中尝试了以下方法,但没有达到预期的效果.
and have tried the following in my setup but its not having the desired effect.
options.AddUserProfilePreference("profile.block_third_party_cookies", false);
options.AddUserProfilePreference("security.cookie_behavior", 0);```
这是我的设置代码
new DriverManager().SetUpDriver(new ChromeConfig());
var options = new OpenQA.Selenium.Chrome.ChromeOptions { };
options.AddArgument("–no-sandbox");
options.AddArguments("-disable-gpu");
options.AddArguments("-disable-dev-shm-usage");
options.AddArgument("-incognito");
options.AddArgument("-start-maximized");
options.AddUserProfilePreference("security.cookie_behavior", 0);
CurrentWebDriver = new ChromeDriver(options);
推荐答案
我遇到了同样的问题.我发现使用以下内容对我有帮助:
I ran into the same issue. I found that using the following helped me:
options.AddUserProfilePreference("profile.cookie_controls_mode", 0);
帮助我找到这个的建议是检查 Chrome 首选项文件(在我的例子中 C:Users<user>AppDataLocalGoogleChromeUser DataDefaultPreferences代码>).我保存了一个阻止 cookie 的副本,然后将设置更改为允许所有 cookie 并比较两个版本,这对我来说突出显示了受影响的控件.
The advice that helped me find this, was to check the Chrome preferences file (in my case C:Users<user>AppDataLocalGoogleChromeUser DataDefaultPreferences). I saved a copy with cookies blocked, then changed the setting to allow all cookies and compared the two versions, and that highlighted the affected control for me.
这篇关于C# Selenium/ChromeDriver 添加用户配置文件首选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C# Selenium/ChromeDriver 添加用户配置文件首选项
基础教程推荐
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
