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

How to send email from current Outlook instance using Java + VBScript

If we are using .Net, we can easily access outlook and send emails using its own libraries. But what if we are using Java? Here we can seek ...