c# - Selenium 禁用恢复页面弹出

标签 c# google-chrome selenium selenium-chromedriver

我正在使用 selenium C#,我试图禁用“崩溃”chrome 的弹出窗口: /image/xudon.png

我尝试设置配置文件首选项,但它似乎根本没有改变,代码:

        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/

相关文章:

C# 按钮文本和调整大小

c# - 在 C# 中定义和访问选定属性的最佳方式是什么?

javascript - 为什么我无法访问 Chrome 内置函数 $?

javascript - 如何在 Chrome 上替换已弃用的 "svgElement.offsetWidth/height"

java - Selenium 似乎可以工作,但随后出现超时错误?

c# - StringTemplate 中的嵌套循环

c# - ASP.NET MVC 自定义 View 路由

jquery-ui - 无法在 Chrome 或 IE 中使用 anchor 链接内的图像进行拖动

java - Selenium 只执行循环的 if != null 部分,不运行循环的 "else if null "部分

java - 在 teSTLink 中执行测试时如何使用断言和测试