Java Selenium将PDF下载到默认文件夹(下载),但不在chromePrefs中指定的文件夹中

Java Selenium将PDF下载到默认文件夹(下载),但不在chromePrefs中指定的文件夹中,java,selenium,google-chrome,selenium-webdriver,Java,Selenium,Google Chrome,Selenium Webdriver,在我的自动化框架中使用Selenium Java并尝试从Chrome下载PDF,下面是我的代码: System.setProperty("webdriver.chrome.driver", "resources/drivers/chromedriver.exe"); ChromeOptions options = new ChromeOptions(); HashMap&l

在我的自动化框架中使用Selenium Java并尝试从Chrome下载PDF,下面是我的代码:

        System.setProperty("webdriver.chrome.driver", "resources/drivers/chromedriver.exe");
        
        ChromeOptions options = new ChromeOptions();
        
        HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
        chromePrefs.put("profile.default_content_settings.popups", 0);
        chromePrefs.put("plugins.always_open_pdf_externally", true);
        chromePrefs.put("download.default_directory", "C:");
        options.setExperimentalOption("prefs", chromePrefs);
        
        driver = new ChromeDriver(options);
System.setProperty(“webdriver.chrome.driver”、“resources/drivers/chromedriver.exe”);
ChromeOptions选项=新的ChromeOptions();
HashMap chromePrefs=新HashMap();
chromePrefs.put(“profile.default\u content\u settings.popups”,0);
chromePrefs.put(“plugins.always\u open\u pdf\u externally”,true);
chromePrefs.put(“下载.默认目录”,“C:”);
选项。设置实验选项(“prefs”,chromePrefs);
驱动程序=新的色度驱动程序(可选);
我指定了位置“C:”(仅用于测试目的),但问题是它在下载文件夹中下载PDF


还有一种方法可以指定我要下载的文件名吗?

我解决了这个问题,问题是不建议使用“C:”或“Desktop”或相对路径之类的文件夹,这就是它不起作用的原因。

有一个类似的答案。@arundeep chohan,正如您所看到的,我的代码看起来几乎一样,但它仍然保存不在指定目录中的文件