我正在尝试在 Microsoft Edge 上运行自动化测试,但遇到了从浏览器弹出的通知问题,该通知导致测试在 HTML 中查找元素时失败,它看起来像上下文测试转移到该通知而不是浏览器本身。
到目前为止我已经尝试过这些解决方案,但没有效果:
edge_options = EdgeOptions()
edge_options.use_chromium = True
edge_options.add_experimental_option("prefs", {
"profile.default_content_setting_values.notifications": 2,
"profile.default_content_setting_values.popups": 2
})
edge_options = EdgeOptions()
edge_options.use_chromium = True
edge_options.add_argument('--disable-notifications')
您可以尝试通过配置标志来关闭
Show feature and workflow recommendations
。还有这样的事情:
string driverpath = @"D:\EdgeDriver\119.0.2151.58";
var service = EdgeDriverService.CreateDefaultService(driverpath);
EdgeOptions options = new EdgeOptions();
options.AddUserProfilePreference("user_experience_metrics", new
{
personalization_data_consent_enabled = true
});
options.AddArgument("--disable-features=msEdgeEnableNurturingFramework");
options.AddArgument("--start-maximized");
WebDriver driver = new EdgeDriver(service, options);
driver.Url = "https://www.google.com";
希望这可以帮助你。