title: Download an Image Using Selenium Webdriver in Python
body: <p>I am trying to download an image from a URL using Selenium Webdriver in Python. The site is protected by a login page, so can't just save the URL contents using requests. I am able to get text from the site after logging in, but I can't figure out how to save an image.</p>
  <p>After I log in to the site, I can do <code>browser.save_screenshot(filename + '.png')</code> but that image is not the correct size as the original.</p>
  <p>The code that I have now is this:</p>
  <pre><code>browser = webdriver.Chrome('../chromedriver')
  browser.get('www.example.com/login')
  # send username and password, click submit
  
  browser.get('www.example.com/123')
  html = browser.page_source
  printData(html)
  
  # this url is an image file
  browser.get('www.example.com/get_photo.php?id=123')
  browser.save_screenshot(filename + '.png')
  </code></pre>
  <p>Ideally I would like to replace the <code>save_screenshot()</code> with something like</p>
  <pre><code>with open(filename + '.jpeg', 'w') as img:
      img.write(browser.download_current_image())
  </code></pre>
  <p>or even something like this, interacting with the popup menu</p>
  <pre><code>browser.right_click()
  browser.down_arrow_key()
  browser.return_key()
  </code></pre>
  <p>or simulating a keypress</p>
  <pre><code>browser.command_key()
  browser.s_key()
  </code></pre>
  <p><a href="https://stackoverflow.com/questions/6813704/how-to-download-an-image-using-selenium-any-version">This</a> question gives the answers that I want, but not for Python. If there is a way to do any of the things suggested in that question (besides taking a screenshot) in Python, that would be a great solution.</p>