JAVA Selenium Webdriver Ask where to save each file before downloading
<p>I am trying to automate file download using Selenium.</p>

<p>Whenever a file is received for download, i want to save that particular file to custom location and save it with custom name.</p>

<p>I want browser to ask to save each file so that i can provide custom path and file name dynamically.</p>

<p>I am able to save the file to custom directory but i could not get control on the file name. I want to use <code>java.awt.Robot</code>, <code>java.awt.datatransfer.StringSelection</code> and <code>java.awt.Toolkit</code> for using custom file name.</p>

<blockquote>
  <p>My code</p>
</blockquote>

<pre><code>ChromeOptions chromeOptions = new ChromeOptions();
HashMap&lt;String, Object&gt; chromePreferences = new HashMap&lt;String, Object&gt;();
chromePreferences.put("profile.default_content_settings.popups", 0);
chromePreferences.put("download.default_directory", browserDownloadDirectoryPath);
chromePreferences.put("safebrowsing.enabled", "true");
chromeOptions.setExperimentalOption("prefs", chromePreferences);
chromeOptions.addArguments("--test-type");
chromeDesiredCapabilities = DesiredCapabilities.chrome();
chromeDesiredCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
</code></pre>

<p>This is saving file to custom folder.</p>

<p>If the browser ask for file saving, i want to use Robot Class to send path.</p>

<pre><code>StringSelection stringSelection = new StringSelection(
                "&lt;file path&gt;" + "&lt;file name&gt;");
Toolkit.getDefaultToolkit().getSystemClipboard()
                .setContents(stringSelection, null);

Robot robot = new Robot();

robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
robot.keyPress(KeyEvent.VK_DOWN);
robot.keyRelease(KeyEvent.VK_DOWN);
robot.keyPress(KeyEvent.VK_DOWN);
robot.keyRelease(KeyEvent.VK_DOWN);
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
</code></pre>

<p>Kindly provide a solution to force browser to ask to save file.</p>

<p>For Firefox, we have <code>about:config</code> to see all preferences for the browser. Do we have something like this for other browsers as well?</p>