i would like to download file in pdf with selenium edge web driver in specific custom folder in c# selenium

Rakesh kumar 106 Reputation points
2022-04-20T19:15:11.69+00:00

I am new to selenium and i would like to download file in pdf with selenium edge web driver in specific custom folder. In default the file is downloading in browser specified download path. Any one suggest the best solution for downloading file in custom path in C# Selenium.

Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Jack J Jun 25,296 Reputation points
    2022-04-21T04:59:39.083+00:00

    @Rakesh kumar , Welcome to Microsoft Q&A. you could try the following code to download file to specific custom folder by using selenium.

    var options = new ChromeOptions();  
        string downloadFilePath = @"E:\Test";  
        options.AddUserProfilePreference("download.default_directory", downloadFilePath);  
        options.AddUserProfilePreference("intl.accept_languages", "nl");  
        options.AddUserProfilePreference("disable-popup-blocking", "true");  
        // declare driver with these options  
        var driver = new ChromeDriver(AppDomain.CurrentDomain.BaseDirectory, options);  
        driver.Navigate().GoToUrl("https://www.microsoft.com/en-us/download/details.aspx?id=25150");  
        var reportDownloadButton = driver.FindElement(OpenQA.Selenium.By.CssSelector("div[itemtype='http://schema.org/Offer']"));  
        reportDownloadButton.Click();  
    

    I used website instead of pdf, but they are fundamentally the same.

    Website:

    194909-image.png

    Hope the above code could help you.

    Best Regards,
    Jack


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.