我正在使用 selenium C#,我试图禁用“崩溃”chrome 的弹出窗口:
我尝试设置配置文件首选项,但它似乎根本没有改变,代码:
ChromeOptions options = new ChromeOptions();
options.AddUserProfilePreference("exit_type", "Normal");
options.AddUserProfilePreference("exited_cleanly", "true");
IWebDriver driver = new ChromeDriver(options);
我尝试将退出类型的值更改为无和无,但在首选项文档中没有任何更改。
最佳答案
我正在使用 C#,我注意到只有当我们使用 Close() 方法然后在 finally block 中使用 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)
{
}
}
关于c# - Selenium 禁用恢复页面弹出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51269896/