Home > Blockchain >  Changing download directory for edge using Python selenium
Changing download directory for edge using Python selenium

Time:06-13

I am able to change the download directory for Chrome using Python Selenium as follows:

DownloadPath = (f'C:\\Users\\{EmplyID}\\Desktop\\General Orders\\{Newfolder}')
chromeOptions = Options()
chromeOptions.add_experimental_option("prefs", {"download.default_directory": DownloadPath})

driver = webdriver.Chrome(executable_path=f'C:\\Users\\{EmplyID}\\Desktop\\General 
Orders\\Bidman To Enovia\\chromedriver.exe',options=chromeOptions)

But I am unable to do the same for edge web driver. It would be great if anyone can help me with the code.

Thanks in advance. :)

CodePudding user response:

 1. Download the correct version of Edge WebDriver from [here][1]. Make
    sure that the Edge WebDriver version is the same as the Edge browser
    version.

  [1]: https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/


 2. Install the MS Edge Selenium tools using command below:

    `pip install msedge-selenium-tools selenium==version e.eg 3.141.4`

 3. Run the following sample python code to test:

    from msedge.selenium_tools import Edge, EdgeOptions
    
    options = EdgeOptions()
        
    options.use_chromium = True
        
    options.add_experimental_option("prefs", {"download.default_directory": r"D:\Downloads"})
    
    
    driver = Edge(executable_path=r"D:\webdriver\msedgedriver.exe", options=options)
        
    driver.get("https://www.seleniumhq.org/download/");
        
    m = driver.find_element_by_link_text("32 bit Windows IE")
        
    m.click()


**Note**: Change the paths in the code to your owns.

CodePudding user response:

You can use the code below to change download directory for Edge. I use Selenium version 4.1.5. I suggest you also use Selenium 4:

from selenium import webdriver
from selenium.webdriver.edge.service import Service

ser = Service("E:\\webdriver\\msedgedriver.exe")
edge_options = webdriver.EdgeOptions()
edge_options.use_chromium = True
download_path = r'C:\mydownloadpath\Download'
edge_options.add_experimental_option('prefs', {
"download.default_directory": download_path
})

driver = webdriver.Edge(service = ser,options = edge_options )
driver.get('http://www.somesite.com')

Note: Please change the paths in the code to your owns.

  • Related