For this same error there are many questions in Stackoverflow. But none of them solved my problem. So I have to post this again.
My Code:
ChromeOptions options = new ChromeOptions();
options.AddArguments("--disable-gpu");
options.AddArguments("--disable-extensions");
options.AddArgument(@"user-data-dir=C:\Users\myname\AppData\Roaming\Chrome\Profile 6");
options.AddArgument("--profile-directory=Profile 6");
IWebDriver driver = new ChromeDriver(options);
driver.Navigate().GoToUrl("https://google.com");
Initially I was getting an error " Unable to move cache folder, access denied."
then I have added the line options.AddArguments("--disable-gpu");
and the error is gone.
Now my Code is opening the browser with profile : "Profile 6". But after that its throwing the error
Error in the line : IWebDriver driver = new ChromeDriver(options);
"Exception thrown: 'OpenQA.Selenium.WebDriverException' in WebDriver.dll An unhandled exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir "
I have already read almost all topics related to this error. Few of them are :
How to open a Chrome Profile through --user-data-dir argument of Selenium
I am stuck in this problem for more than a week now. Please help.
EDIT:
To confirm that I am not using the already opened default user profile, I checked Cheome://version
to confirm the user data directory path. Its different than the default.
Also I tried to to run the code after closing all the open chrome instances. This Time I have not received the error. The browser opened by the webdriver. But after that nothing happened. The code got time out error after 60 seconds in the line : IWebDriver driver = new ChromeDriver(options);