C#Selenium Edge驱动程序无法下载文件-显示Keep文件提示



我将C#与Selenium一起用于QA自动化,下载.xml文件时遇到问题,因为总是会出现一个提示,询问我是否要保留该文件。它还会打开第二个选项卡来执行下载,并在提示出现后关闭它。[保持文件提示][1]

使用Chrome时,我看不到这种行为。我到处找了找,找不到能够处理这个问题的EdgeOptions((和/或AddArguments((。

有什么想法吗?

您需要使用JS与另一个浏览器中的元素进行交互。我有这样的经验,我在处理这个问题的方法中使用了if-else语句。只要看看Selenium文档,JS中的Selenium示例,等等。

只需将其添加到OneTimeSetup方法中即可。请确保以管理员身份运行Visual Studio。这是从Edge 105+开始工作的:

public void SetEdgeXmlDownloadPolicy()
{
var keyName = "Software\Policies\Microsoft\Edge\";
var valueName = "ExemptFileTypeDownloadWarnings";
var valueData = @"{""domains"": ["" * ""], ""file_extension"": ""xml""}";
var currentUser = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64);
var currentKey = currentUser.OpenSubKey(keyName, true);
if (currentKey == null)
currentKey = currentUser.CreateSubKey(keyName);
if (currentKey.GetValue(valueName) == null)
currentKey.SetValue(valueName, valueData);           
}

相关内容

最新更新