c# - Selenium 禁用恢复页面弹出窗口
问题描述
我正在使用 selenium C#,我正在尝试禁用“崩溃”chrome 的弹出窗口:
我试图设置配置文件首选项,但似乎它根本没有改变,代码:
ChromeOptions options = new ChromeOptions();
options.AddUserProfilePreference("exit_type", "Normal");
options.AddUserProfilePreference("exited_cleanly", "true");
IWebDriver driver = new ChromeDriver(options);
我尝试将退出类型的值更改为无和无,但在首选项文档中没有任何更改。
解决方案
我正在使用 C#,我注意到只有在 finally 块中使用 Close() 方法后跟 Quit() 时才能关闭 Chrome 驱动程序。不需要特殊选项。我认为在java中它是相同的方式。这将有助于在使用驱动程序启动 chrome 时摆脱“恢复页面”
ChromeOptions options = new ChromeOptions();
options.AddArgument(Configure.chromeProfileDir);
options.AddArgument(Configure.chromePath);
ChromeDriver d = null;
try
{
d = new ChromeDriver(options);
d.Navigate().GoToUrl("https://google.com");
// Your operations...
}
catch(Exception e)
{
// Handle your exceptions...
}
finally
{
try
{
d.Close();
d.Quit();
}
catch(Exception e)
{
}
}
推荐阅读
- angularjs - DOM 与应用程序
- ibm-mq - IBM MQ qmgr 无法在 Windows 10 上启动,错误为 AMQ6119:发生内部 IBM MQ 错误 () exitvalue = 71
- flutter - Flutter 中的 SwiftUI 环境对象替代方案
- css - CSS - 仅设置第 3 和第 5 个 h2 元素的样式
- ruby-on-rails - Rails 如何确定 Rails.configuration.root?
- javascript - Nodejs Secure Websocket 因 SSL_ERROR_BAD_CERT_DOMAIN 而失败
- android - SecurityException - GoogleCertificatesRslt:不允许
- javascript - 为什么带有 getter/setter 的 Es6 类中的记忆不起作用?
- amazon-web-services - 在 Terraform 中动态更改状态键
- javascript - 在动画期间更改 CSS