Efe
Efe

Reputation: 880

Selenium: Open two different instances of ChromeDriver with same profile

I am trying to open two instances ChromeDriver with the same profile as follow:

ChromeDriverService service1 = ChromeDriverService.CreateDefaultService();
ChromeOptions options1 = new ChromeOptions();
options1.AddArguments($"user-data-dir=C:/Users/{Environment.UserName}/AppData/Local/Google/Chrome/User Data/Default");
service1.HideCommandPromptWindow = true;
ChromeDriver driver1 = new ChromeDriver(service1, options1);
driver1.Navigate().GoToUrl("https://www.google.com");

ChromeDriverService service2 = ChromeDriverService.CreateDefaultService();
ChromeOptions options2 = new ChromeOptions();
options2.AddArguments($"user-data-dir=C:/Users/{Environment.UserName}/AppData/Local/Google/Chrome/User Data/Default");
service2.HideCommandPromptWindow = true;
ChromeDriver driver2 = new ChromeDriver(service2, options2);
driver2.Navigate().GoToUrl("https://www.google.com");

The problem is that the first driver works and navigates to Google, but in second, I get the following exception when instantiating the second driver:

Additional information: A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://localhost:6949/session. The status of the exception was ReceiveFailure, and the message was: The underlying connection was closed: An unexpected error occurred on a receive.

I also executed each driver from different binaries, but got the same problem with the second one.

The problem is caused by user profile(Chrome options), and by removing profile, everything works fine.

But, for me, using the same profile is mandatory.

Any guidance will help.

Thanks.

Upvotes: 2

Views: 4358

Answers (1)

Shubham Jain
Shubham Jain

Reputation: 17553

This may be happening because you are using a single file for profiling.

I have found an article where you can find steps to duplicate an profile. Follow the instructions and pass the copy of profile in 2nd instance of webdriver.

article link :-

https://support.4it.com.au/article/copy-google-chrome-profile-new-user-profile-windows/

Hope it will help you :)

Upvotes: 1

Related Questions