Pythoner Pythoner - 10 days ago 6
Python Question

Save the file to my folder using Selenium?

I am trying to save the downloaded file from the website into my personal desktop folder but the file still gets saved in the Downloads folder. I do not know why Python is doing that. Python does not even display an error. Can someone please provide advice on what is the mistake here.

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options

driver = webdriver.Chrome("C:\Python27\Scripts\chromedriver.exe")
driver.get("https://etrakit.friscotexas.gov/Search/permit.aspx")

number_option = driver.find_element_by_id("cplMain_btnSearch")
number_option.click()

delay = 3
try:
WebDriverWait(driver, delay).until(EC.visibility_of_element_located((By.ID,"cplMain_btnExportToExcel")))
print "Page is ready!"
except TimeoutException:
print "Loading took too much time!"


search_button = driver.find_element_by_id("cplMain_btnExportToExcel")
search_button.click()

options = webdriver.ChromeOptions()
options.add_argument("download.default_directory=C:/Users/Jake/Desktop/Programming/R Files")
driver = webdriver.Chrome(r"C:\Python27\Scripts\chromedriver.exe", chrome_options = options)

driver.close()
driver.quit()

print 'ALL DONE'


When I run the snippet:

Page is ready!
ALL DONE

Answer

Per the post attached, I do not think it is possible to change the download directory.

Selenium Python Chromedriver Change File Download Path

Comments