Якт*_*Тид 6 .net c# selenium google-chrome
你好.如何点击"允许"按钮?我真的找不到互联网上的任何解决方案.我不想使用c ++钩子或通过坐标模拟鼠标点击.是否有任何好方法允许此通知?
new ChromeOptions.AddUserProfilePreference("profile.default_content_setting_values.automatic_downloads", 2);
Run Code Online (Sandbox Code Playgroud)
没有帮助
找到了两个解决方案:
1)感谢@Floren的回答:C#selenium chromedriver单击“允许在此设备上存储文件”
对于 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',
Run Code Online (Sandbox Code Playgroud)
C# 用法:
var chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("--unlimited-storage");
var driver = new ChromeDriver(chromeOptions);
Run Code Online (Sandbox Code Playgroud)
2)@Simon Mourier 的回答C# selenium chromedriver 单击“允许在此设备上存储文件”
使用 .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();
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
424 次 |
最近记录: |