April 12, 2021

How to fix 'user data directory is already in use' exception in selenium

  April 12, 2021

 If we have an SSO application and we want to login to the application with those credentials, we can use a small modification to our driver properties.

Add the following argument to driver options and it will use the existing user credentials.

string loggedInUser = System.Environment.UserName; //read the Logged in user name
driverOptions.AddArguments(@"user-data-dir=C:\Users\" + loggedInUser + @"\AppData\Local\Google\Chrome\User Data");

We may get the below error while continues execution of the scripts using selenium.

OpenQA.Selenium.WebDriverException: 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.

This happens due to the open browser from the previous session. So in order to avoid this issue make sure to close the browser before triggering the script.

If possible, close the browser programmatically before each execution.

logoblog

Thanks for reading How to fix 'user data directory is already in use' exception in selenium

Previous
« Prev Post

No comments:

Post a Comment

Bookmark this website for more workarounds and issue fixes.

Verify Zip file contents without extracting using C# + Selenium

While doing automation testing, we may get a scenario where we need to download a zip file and to validate the contents inside it. One way t...