I try to use selenium in my ASP.NET MVC project, but not for testing, I use selenium in my controller to open new browser and download file after click button in my website. After I click button, the browser is open but selenium driver is not working to navigate to some url(cannot open www.example.com in browser).
this is my code (I write this code in Controller, not in unit test):
private void OpenBrowser()
{
try
{
string strChromeDriver = System.Configuration.ConfigurationManager.AppSettings["BinaryLocationChrome"];
string strdownloadsPath = System.Configuration.ConfigurationManager.AppSettings["DownloadPath"];
var options = new ChromeOptions();
options.AddArgument("disable-blink-features=AutomationControlled");
options.AddArgument("no-sandbox");
options.AddArgument("--remote-debugging-port=0");
options.AddArguments("--incognito", "--disable-popup-blocking", "safebrowsing-disable-download-protection", "allow-unchecked-dangerous-downloads");
options.AddUserProfilePreference("download.default_directory", strdownloadsPath);
options.AddUserProfilePreference("intl.accept_languages", "nl");
options.AddUserProfilePreference("disable-popup-blocking", "true");
options.AddArgument("--log-level=3");
try
{
var driver = new ChromeDriver(strChromeDriver, options);
driver.Navigate().GoToUrl("www.example.com");
}
catch (Exception e)
{
Debug.WriteLine(">> FAILED " + " - " + e.ToString());
}
}
catch (Exception e)
{
Debug.WriteLine("** FAILED ** " + e.ToString());
}
}
Please anyone help me to solve this problem, Thanks.
14