c# - C# selenium chromedriver 点击允许在此设备上存储文件
问题描述
你好。如何点击“允许”按钮?我真的在互联网上找不到任何解决方案。我不想使用 c++ 钩子或通过坐标模拟鼠标点击。有什么好的方法可以允许这个通知吗?
new ChromeOptions.AddUserProfilePreference("profile.default_content_setting_values.automatic_downloads", 2);
没有帮助
解决方案
找到了两个解决方案:
1) 感谢@Floren 的回答:C# selenium chromedriver 点击 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 点击 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();
}