I work with driver´s for Chrome, Firefox and Edge in my Application and have always the same problem. So for this post i reduce my request to the Chrome driver as an example.
What is needed:
- Path to the chromedriver.exe
- Hide the console
- Change of the default Download directory of the browser
Here is a Page that show us the Chrome Driver Class and its options: https://www.selenium.dev/selenium/docs/api/dotnet/html/T_OpenQA_Selenium_Chrome_ChromeDriver.htm
But my 3 needed Points are not listed together.
Here is a snipped of my Code with Commends:
string str_DriverPath = @"C:\_MT5_TOOLS\DRIVER\CHROME";
// hide Console
ChromeDriverService service = ChromeDriverService.CreateDefaultService();
service.HideCommandPromptWindow = true;
//// change Standard-Download-Path
ChromeOptions options = new ChromeOptions();
var downloadDirectory = GlobalVars.RootPath + @"Pool\" + GlobalVars.strSymbol + @"\" + GlobalVars.strSymbol + @"_" + GlobalVars.strPeriod;
options.AddUserProfilePreference("download.default_directory", downloadDirectory);
options.AddUserProfilePreference("download.prompt_for_download", false);
options.AddUserProfilePreference("disable-popup-blocking", "true");
// Start Driver:
//webdriver = new ChromeDriver(service, options); // works fine
//webdriver = new ChromeDriver(str_DriverPath, options); // works fine
webdriver = new ChromeDriver(str_DriverPath, service, options); // will not work
How to combine my 3 Points into one driver?