Search code examples
c#seleniumselenium-webdriverselenium-chromedriverremotewebdriver

Changing Default Download Destination for RemoteWebDriver


Im trying to set the default download directory to some thing like:

_webServerFolderDirectory = @"D:\Web\FreshPlatformRegression1\RegressionTestResources";

but i am having no luck finding anything anything to do so. I can find solutions for ChromeDriver (See the line i commented out) but nothing that'll work with DesiredCapabilities for RemoteWebDriver. Here is what the part the calls up the RemoteWebDriver looks like at the moment:

DesiredCapabilities cap = new DesiredCapabilities();
//cap.AddUserProfilePreference("download.default_directory", _webServerFolderDirectory);
            
cap.SetCapability(CapabilityType.BrowserName, "chrome");
_parallelConfig.Driver = new RemoteWebDriver(new Uri("http://192.168.1.98:4455/wd/hub"), cap);

Solution

  • Incase anyone comes across this issue, I have found a solution. You can use .ToCapabilities() to convert ChromeOptions to capabilities. The code would look similar to this:

    String downloadFilepath = @"\\rslfgweb\FreshPlatformRegression1\RegressionTestResources\PDFReports\";
    ChromeOptions options = new ChromeOptions();
    options.AddUserProfilePreference("download.default_directory", downloadFilepath);
    
    _parallelConfig.Driver = new RemoteWebDriver(new Uri("http://192.168.1.98:4455/wd/hub"), options.ToCapabilities());