【问题标题】:Disable Chrome clipboard popups WebdriverIO禁用 Chrome 剪贴板弹出窗口 WebdriverIO
【发布时间】:2018-04-25 21:30:05
【问题描述】:

我正在尝试使用 webdriverIO (Selenium) 禁用 chrome 剪贴板弹出/通知以实现自动化。我尝试设置 chrome 选项,但它仍然没有禁用它。我想单击此弹出窗口后面的 Web 元素,因此我不希望此弹出窗口出现在自动化中。我尝试手动禁用剪贴板设置,但 selenium 每次都会打开一个新会话来刷新设置。此外,无法使用开发人员工具进行检查。它不是警报,因此接受/关闭警报也不起作用。

browser.alertAccept();

browser.alertDismiss();

chromeOptions: {
    args: [
        'disable-infobars',
        'disable-popup-blocking',
        'disable-notifications'
    ],
    prefs: {
        'profile.default_content_settings.popups' : 2,
        'profile.default_content_settings.notifications' : 2,
    }
}

请帮我解决这个问题,任何帮助将不胜感激。

【问题讨论】:

    标签: javascript google-chrome selenium popup webdriver-io


    【解决方案1】:

    一种解决方法可能是切换到弹出窗口并关闭它。

    driver.switchTo().alert().dismiss();
    

    driver.switchTo().activeElement().dismiss();
    

    编辑:我发现了一个有趣的网站。试试本站末尾的代码:http://blog.amolchavan.space/block-push-notification-on-chrome-in-selenium-webdriver/

    【讨论】:

    • 感谢您的及时回复。该网站也很有趣,但对解决方案没有清楚的了解。我尝试了警报接受和解雇。 browser.alertAccept();但是 webdriverIO 不会将其识别为警报。我认为这与为 clipbaord 设置 chrome 首选项有关。
    • DesiredCapabilities capabilities = DesiredCapabilities.chrome(); ChromeOptions options = new ChromeOptions(); options.addArguments("disable-notifications"); capabilities.setCapability(ChromeOptions.CAPABILITY, options); WebDriver driver = new ChromeDriver(); 不过这对我有用。
    【解决方案2】:

    我看到很多人也建议使用profile.default_content_settings,所以它可能取决于 chrome 版本。当前的 chrome 版本将使用此代码,如下所示

    chromeOptions: {
        prefs: {
            'profile.managed_default_content_settings.popups' : 2,
            'profile.managed_default_content_settings.notifications' : 2,
        }
    }
    

    【讨论】: