0

Is Selenium able to upload an image to a website? I have an automation project (CHROME)that requires me to jump back and forth between tabs, copying elements. A task that is relatively easy with Selenium, but at one point I must click an 'Upload' element that pops up a PC browsing window:

enter image description here

Can I interact with this window using Selenium and upload the desired files to a webpage?

Also is it possible to download images off the web using Selenium? When you right-click on an image, tap "Save As" - Can Selenium navigate the save window to name the location where the file will be saved?

plx23
  • 89
  • 6

1 Answers1

0

set download options for where you want to save file

from selenium.webdriver.chrome.options import Options
opts = Options()
# set options for download
    prefs = {'download.prompt_for_download': False,
             'download.directory_upgrade': True,
             'safebrowsing.enabled': False,
             'safebrowsing.disable_download_protection': True,
             "plugins.always_open_pdf_externally": True
             }
    opts.add_experimental_option("prefs", prefs)

    # initialise the instance of chrome webdriver
    driver =webdriver.Chrome(executable_path=your_chromedriverpath, 
    chrome_options=opts)

for more information here

Manali Kagathara
  • 743
  • 4
  • 11
  • I am quite new to Selenium and coding in general. Could you please elaborate on exactly what this does and how can I edit it so it's specific for my own situation? – plx23 Feb 21 '20 at 08:21
  • `download.prompt_for_download` and `download.directory_upgrade` pertains to the process of downloading where as OP's question is about _upload an image to a website_. – undetected Selenium Feb 21 '20 at 09:48
  • @DebanjanB also mention in question about upload image in a comment and in question also asked *for is it possible to download images off the web using Selenium?* – Manali Kagathara Feb 21 '20 at 09:55