There are two things that are going wrong in code.
For Firefox:
You need to set
profile.setPreference("browser.download.dir", "C:\Users\Admin\Desktop\ScreenShot");
not to
profile.setPreference("browser.download.dir", "C:\Users\Admin\Desktop\ScreenShot\pic.jpeg");
secondly, you are setting preference browser.download.folderlist, it is browser.download.folderList (L caps in folderList).
Once you have achieved this both, you can use then your Robot class to perform desired operations.
For Chromedriver try out with:
String downloadFilepath = "/path/to/download";
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", downloadFilepath);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(cap);
Hope this helps. :)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…