Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在使用JavaSelenium和chromedriver时拒绝或阻止chrome弹出窗口?_Java_Selenium_Selenium Webdriver_Selenium Chromedriver_Popup - Fatal编程技术网

如何在使用JavaSelenium和chromedriver时拒绝或阻止chrome弹出窗口?

如何在使用JavaSelenium和chromedriver时拒绝或阻止chrome弹出窗口?,java,selenium,selenium-webdriver,selenium-chromedriver,popup,Java,Selenium,Selenium Webdriver,Selenium Chromedriver,Popup,我面临的问题是,每当我的程序想要进入一个特定的网站时,就会出现一个chrome弹出窗口,请求允许在我不想安装的应用程序中继续。我要么想拒绝该权限,要么通常会阻止它,导致它根本不出现。 我已经测试过类似帖子中提供的一些解决方案,但我无法让它们发挥作用,我是一个新手,非常感谢您的帮助 这是我的密码: @SuppressWarnings("deprecation") public static void methodOne() throws InterruptedExcep

我面临的问题是,每当我的程序想要进入一个特定的网站时,就会出现一个chrome弹出窗口,请求允许在我不想安装的应用程序中继续。我要么想拒绝该权限,要么通常会阻止它,导致它根本不出现。 我已经测试过类似帖子中提供的一些解决方案,但我无法让它们发挥作用,我是一个新手,非常感谢您的帮助

这是我的密码:

@SuppressWarnings("deprecation")
    public static void methodOne() throws InterruptedException {
        System.setProperty("webdriver.chrome.driver", "C:...\\chromedriver_win32\\chromedriver.exe");
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--disable-gpu ", "--window-size=1344,840","--ignore-certificate-errors");
        options.addArguments("--disable-popup-blocking");
        options.addArguments("incognito");
        options.addArguments("test-type");
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
        driver = new ChromeDriver(capabilities);
        driver.manage().timeouts().implicitlyWait(15,TimeUnit.SECONDS);
public void invokeBrowser(){
//为无通知弹出窗口设置Google Chrome选项
Map prefs=新的HashMap();
prefs.put(“profile.default\u content\u setting\u values.notifications”,2);
ChromeOptions选项=新的ChromeOptions();
选项。设置实验选项(“prefs”,prefs);
//初始化WebDriver
System.setProperty(“webdriver.chrome.driver”,chromeDriverLocation);
驱动程序=新的色度驱动程序(可选);
}

你能分享到该网站的链接吗?不是真的,但你可以想象它像facebook一样工作,chrome要求你继续在facebook应用程序中而不是浏览器中。我还可以想象有更多详细信息的帖子,我甚至看到过一些。但您不必这样做,我不使用Selenium,但这听起来像协议处理程序配置。您可能有幸搜索到如何禁用“协议处理程序”,例如,尽管我遵循了您的建议,但弹出窗口仍然以某种方式出现(
public void invokeBrowser() {
        
        // Setting up Google Chrome options for no notification popup
        Map<String, Object> prefs = new HashMap<String, Object>();
        prefs.put("profile.default_content_setting_values.notifications", 2);
        ChromeOptions options = new ChromeOptions();
        options.setExperimentalOption("prefs", prefs);

        //Initializing the WebDriver
        System.setProperty("webdriver.chrome.driver",chromeDriverLocation);
        driver = new ChromeDriver(options);

    }