2

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

InvalidArgumentException: Message: invalid argument: user data directory is already in use error using --user-data-dir to start Chrome using Selenium

How to initiate a new Chrome session when the default session is already running using ChromeDriver and Chrome through Selenium and Python

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);

Arijit
  • 1,633
  • 2
  • 21
  • 35
  • you sure the roaming directory contains your current user's profile directory? – pcalkins Jun 02 '20 at 16:49
  • Yes I checked that. I have edited my question. Please check. I have 3 years of Selenium experience. I never faced this before. I am really frustrated now. – Arijit Jun 02 '20 at 17:18
  • does your default profile path say it's in the roaming directory? This info is usually shared across all users... I think when Chrome starts, it grabs data from roaming and applies it to the current user's profile. You don't need to set that path. – pcalkins Jun 02 '20 at 17:50
  • Yes My Default profile path is in roaming directory. I tried with not setting the path. Still same error. – Arijit Jun 02 '20 at 18:45
  • if you comment out the options lines setting profile paths, does it work or are you seeing the same timeout? – pcalkins Jun 02 '20 at 19:20
  • As I mentioned in the question removing --disable-gpu is giving error : Unable to move cache folder, access denied. Removing --disable-extensions is giving error while running the code with out any existing chrome instance. – Arijit Jun 02 '20 at 19:29
  • I'm curious if it runs OK without these lines: options.AddArgument(@"user-data-dir=C:\Users\myname\AppData\Roaming\Chrome\Profile 6"); options.AddArgument("--profile-directory=Profile 6"); If it does not I wouldn't run as a roaming user. – pcalkins Jun 02 '20 at 19:34

1 Answers1

0

Possibly you are specifying the wrong directory. Instead of:

C:\Users\myname\AppData\Roaming\Chrome\Profile 6

You need to pass:

C:\Users\myname\AppData\Local\Chrome\Profile 6

So the effective line of code will be:

options.AddArgument(@"user-data-dir=C:\Users\myname\AppData\Local\Chrome\Profile 6");

Update 1

Additionally, you can remove the argument --profile-directory as in:

options.AddArgument("--profile-directory=Profile 6");  

Update 2

If I close all the chrome instances and run the code, I am not getting this error means ChromeDriver is able to open the Chrome browsing instance perfectly. But to analyze why nothing happened can be interpreted from the TRACE level logs.

Ensure that:

  • JDK is upgraded to current levels JDK 8u251.
  • Selenium is upgraded to current levels Version 3.141.59.
  • ChromeDriver is updated to current ChromeDriver v83.0 level.
  • Chrome is updated to current Chrome Version 83.0 level. (as per ChromeDriver v83.0 release notes)
  • If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
  • Take a System Reboot.
  • Execute your @Test as non-root user.
  • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks for the answer. My chrome://version/ says the Profile Path is C:\Users\myname\AppData\Roaming\Chrome\Profile 6. However I see the /AppData/Local folder also have user profiles. So I tried with your option. But getting same eror. – Arijit Jun 02 '20 at 18:37
  • @Arijit Check out the answer update and let me know the status. – undetected Selenium Jun 02 '20 at 18:53
  • After removing the --profile-directory, The chrome is opening with the default user profile and I'm getting same error. Please check the last edit of my question. If I close all the chrome instances and run the code, I am not getting this error. one instance of chrome is opening perfectly by the webdriver. But the URL is not opening. and the code is getting time out error after 60 seconds. – Arijit Jun 02 '20 at 19:18
  • @Arijit Checkout the answer update and let me know the status. – undetected Selenium Jun 02 '20 at 20:05
  • I'm using C#. my selenium and chrome driver nuget packages are latest. – Arijit Jun 02 '20 at 20:08