[英]C# selenium chromedriver click on Allow store files on this device
找到两个解决方案
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',
C#用法:
var chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("--unlimited-storage");
var driver = new ChromeDriver(chromeOptions);
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();
}
你不能,这是一个操作系统级别的对话,而不是DOM内部的东西。
解决这个问题的方法是使用所需的功能来配置chrome以不显示此对话框。
我打算建议
ChromeOptions options = new ChromeOptions();
options.AddUserProfilePreference("download.prompt_for_download", 0);
options.AddUserProfilePreference("settings.labs.advanced_filesystem", 1);
如果AddUserProfilePreference
不起作用,添加选项的其他潜在命令将是:
AddLocalStatePreference
AddAdditionalChromeOption
AddAdditionalCapability
有关所需功能和chrome的更多详细信息,请查看:
var chromeOptions = new ChromeOptions();
var downloadDirectory = @"C:\Users\";
chromeOptions.AddUserProfilePreference("download.default_directory", downloadDirectory);
chromeOptions.AddUserProfilePreference("download.prompt_for_download", false);
chromeOptions.AddUserProfilePreference("disable-popup-blocking", "true");
chromeOptions.AddUserProfilePreference("profile.default_content_setting_values.automatic_downloads", 1);
IWebDriver _driver = new ChromeDriver(chromeOptions);
你能试试这个吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.