Home > Mobile >  How to specify the folder when downloading a file with slelenium python
How to specify the folder when downloading a file with slelenium python

Time:12-01

Here's my code :

from selenium import webdriver
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait     
from selenium.webdriver.common.by import By     
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys

PATH = "driver\chromedriver.exe"

options = webdriver.ChromeOptions() 

p = {"download.default_directory": "C:\\Users", "safebrowsing.enabled":"false"}
options.add_experimental_option("prefs", p)

driver = webdriver.Chrome(options=options, executable_path=PATH)

url = 'https://www.mergermarket.com/homepage'

driver.get(url)

download = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="__next"]/div/div/div[1]/div/div[2]/div[1]/div/div/div[2]/button[1]')))
download.click()

I made some research but almost everyone recommende to use download.default_directory with ChromeOptions. I did like you can see above but it didn't work. Well, the code work but my file is downloaded in download and not the path I specified in my code.

CodePudding user response:

You can copy automatically downloaded file in author path with os or shutill librarie in python

  • Related