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.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,627 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jack J Jun 24,496 Reputation points Microsoft Vendor
    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