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.


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

« Prev Post

No comments:

Post a Comment

Fixing javascript error: Cannot read properties of null (reading 'querySelector') issue when using CSS identifier in selenium

 JavaScript is another way to interact with web elements when normal selenium methods fail to act. But one issue with javascript is, it does...