title: Python 3 Chrome Selenium Keep Downloaded Jar File
body: <p>I'm using Selenium, Chrome, and Python 3.</p>
  <p>Here's what I'm doing to set everything up</p>
  <pre><code>import os
  from selenium import webdriver
  from selenium.webdriver.chrome.options import Options
  import time
  
  chrome_options = Options()
  
  options = webdriver.ChromeOptions()
  
  prefs = {
      &quot;download.default_directory&quot;: r&quot;C:\Download\Dir&quot;,
      &quot;download.directory_upgrade&quot;: &quot;true&quot;,
      &quot;download.prompt_for_download&quot;: &quot;false&quot;,
      &quot;disable-popup-blocking&quot;: &quot;true&quot;,
      'download.neverAsk.saveToDisk':   'application/octet-stream, application/json, jar, ' +
                                                  'text/comma-separated-values, text/csv, application/csv, ' +
                                                  'application/excel, application/vnd.ms-excel, ' +
                                                  'application/vnd.msexcel, text/anytext, text/plaintext, ' +
                                                  'image/png, image/pjpeg, image/jpeg, application/zip',
      &quot;safebrowsing.enabled&quot;: True
  }
  options.add_experimental_option(&quot;prefs&quot;, prefs)
  driver = webdriver.Chrome(options=options)
  chrome_options.add_argument('--disable-gpu')
  chrome_options.add_argument('--disable-software-rasterizer')
  chrome_options.add_argument('--safebrowsing-disable-download-protection')
  </code></pre>
  <p>Then I have some credential secrets imported, and some website navigation to get to the file to download.</p>
  <p>Afterwards, I click on the link to download the file:</p>
  <pre><code># Click Upgrade Jar File
  driver.find_element_by_xpath('//a[@id=&quot;accordionPanel:j_id_3a:1:j_id_3j&quot;]').click()
  </code></pre>
  <p>The problem I have is here. Chrome asks me if I'd like to keep the jar file after I've downloaded it.</p>
  <hr />
  <p><a href="https://i.stack.imgur.com/Jxx5Z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Jxx5Z.png" alt="enter image description here" /></a></p>
  <hr />
  <p>I've been reading through a lot of documentation and I don't understand how I can circumvent this. I  believe that it should be added to <code>prefs</code> or as an <code>chrome_options.add_argument</code> but so far I've had no luck with the options I've found.</p>
  <hr />
  <h2>Update 01:</h2>
  <p>A little update, I was able to get it to work &quot;silently&quot;, which allows you to bypass the &quot;keep&quot; button, but I haven't yet found a solution that will bypass the &quot;keep&quot; button when you're looking at the GUI.</p>
  <pre><code>options = webdriver.ChromeOptions()
  
  prefs = {
      &quot;download.default_directory&quot;: r&quot;C:\Download\Dir&quot;,
      &quot;download.directory_upgrade&quot;: &quot;true&quot;,
      &quot;download.prompt_for_download&quot;: &quot;false&quot;,
      &quot;disable-popup-blocking&quot;: &quot;true&quot;,
      &quot;safebrowsing.enabled&quot;: False,
      &quot;default_content_settings&quot;: &quot;contentSettings&quot;,
      &quot;download&quot;: &quot;download&quot;
  }
  options.add_experimental_option(&quot;prefs&quot;, prefs)
  options.add_argument(&quot;--headless&quot;)
  options.add_argument(&quot;--disable-notifications&quot;)
  options.add_argument('--disable-gpu')
  options.add_argument('--disable-software-rasterizer')
  driver = webdriver.Chrome(options=options)
  options.add_argument('--safebrowsing-disable-download-protection')
  </code></pre>
  <hr />
  <h2>Update 02</h2>
  <p>Adapted code from a comment:</p>
  <pre><code>from selenium import webdriver
  from selenium.webdriver.chrome.options import Options
  from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
  import time
  import os
  
  # Secrets
  user_id = [grabs from a function that queries secrets]
  user_password = [grabs from a function that queries secrets]
  download_dir = &quot;C:\Download\Dir&quot;
  
  options = Options()
  options.add_argument(&quot;--disable-infobars&quot;)
  options.add_argument(&quot;start-maximized&quot;)
  options.add_argument(&quot;--disable-extensions&quot;)
  options.add_argument(&quot;--disable-popup-blocking&quot;)
  
  # disable the banner &quot;Chrome is being controlled by automated test software&quot;
  options.add_experimental_option(&quot;useAutomationExtension&quot;, False)
  options.add_experimental_option(&quot;excludeSwitches&quot;, ['enable-automation'])
  
  
  prefs = {
      &quot;download.default_directory&quot;: r&quot;C:\Download\Dir&quot;,
      'download.prompt_for_download': False,
      'download.extensions_to_open': 'jar',
      'safebrowsing.enabled': True
  }
  
  capabilities = DesiredCapabilities().CHROME
  options.add_experimental_option('prefs', prefs)
  capabilities.update(options.to_capabilities())
  
  driver = webdriver.Chrome('.\chromedriver.exe', options=options)
  
  url = 'URL GOES HERE'
  
  driver.get(url)
  
  print(&quot;Navigating to&quot;, url)
  driver.get(url)
  
  # Define Text Boxes For Login
  print('Logging into GoAnywhere Website')
  username = driver.find_element_by_id('email')
  password = driver.find_element_by_name('secret')
  
  # Enter Username/Password
  username.send_keys(user_id)
  password.send_keys(user_password)
  password.send_keys('\n')
  
  # Wait for Page to load
  </code></pre>
  <p>....[Navigation Logic Here]....</p>
  <pre><code># Click Upgrades
  print(&quot;Selecting Upgrades&quot;)
  time.sleep(1)
  driver.find_element_by_xpath('//div[@id=&quot;accordionPanel&quot;]/div[5]').click()
  
  # CLick Upgrade Jar File
  time.sleep(1)
  print(&quot;Downloading upgrade jar to&quot;, download_dir)
  driver.find_element_by_xpath('//a[@id=&quot;accordionPanel:j_id_3a:1:j_id_3j&quot;]').click()
  </code></pre>
  <p>....[Logic to do stuff with file after downloaded]....</p>
  <hr />