C# selenium chromedriver 单击允许在此设备上存储文件

标签 c# .net selenium google-chrome

enter image description here

嗨。 我怎样才能点击“允许”按钮?我真的无法在互联网上找到任何解决方案。我不想使用 C++ 钩子(Hook)或通过坐标模拟鼠标点击。有什么好的方法可以允许这个通知吗?

new ChromeOptions.AddUserProfilePreference("profile.default_content_setting_values.automatic_downloads", 2);

没有帮助

最佳答案

找到两个解决方案:

1) 感谢@Floren 的回答:C# selenium chromedriver click on Allow store files on this device

Chromium 有一个参数--unlimited-storage

Chromium 源代码引用:

// Overrides per-origin quota settings to unlimited storage for any
// apps/origins.  This should be used only for testing purpose.
const char kUnlimitedStorage[] = "unlimited-storage";



# Prevent the infobar that shows up when requesting filesystem quota.
    '--unlimited-storage',

C# 用法:

var chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("--unlimited-storage");
var driver = new ChromeDriver(chromeOptions);

2) @Simon Mourier 的回答 C# selenium chromedriver click on Allow store files on this device

使用 .NET UIAutomation 单击“允许”按钮

var andCondition = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Allow"));

AutomationElement chromeWindow = AutomationElement.FromHandle(_windowPointer); // IntPtr type
var buttonsFound = chromeWindow.FindAll(TreeScope.Descendants,  andCondition);
if (buttonsFound.Count > 0)
{
   var button = buttonsFound[0];
   var clickPattern = button.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
   clickPattern.Invoke();
}

关于C# selenium chromedriver 单击允许在此设备上存储文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54755558/

相关文章:

c# - 什么是支持 LINQ 的 "mobile".NET 数据库?

c# - 如何通过 C# 使用 AutoIT 库中的 WinSetState 函数

java - 如何使用 selenium webdriver 在 IE10 中下载文件?

javascript - ByChained 未定义

c# - EPPlus 中的自动列宽

c# - 在 C# 类库中使用 MATLAB MWArray.dll

c# - 在没有 Json.Net 的情况下反序列化 Json 字符串(在 C# 中)

c# - 在 LINQ 中表达组查询时遇到问题

java - JUNIT 5 报告自动折叠

c# - 在 C# 和 ASP.NET 中跟踪对性能有何影响?