嗨。 我怎样才能点击“允许”按钮?我真的无法在互联网上找到任何解决方案。我不想使用 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/