Warm tip: This article is reproduced from serverfault.com, please click

Selenium Launch a new instance of Edge (Chromium) using the current Profile

发布于 2021-06-06 23:16:04

I'm using C# / Selenium 3 to launch and control instances of Edge (Chromium). One of the requirements I have is that any instance of Edge launched by my code should use the default profile (The one that Edge uses if you open it normally). I can do this with one instance of Edge by using the user-data-dir argument. But if I try to launch another instance then I get an several errors in the new web driver window (Access is denied, Unable to create Cache, Error reading broker pipe: The pipe has been ended). I'm guessing the user-data-dir is in use by the first instance. Do I need to create a copy of the profile some how?

EdgeDriverService edgeDriverService = EdgeDriverService.CreateChromiumService(webDriverPath);
edgeDriverService.HideCommandPromptWindow = !debug;

EdgeOptions edgeOptions = new ()
{
    UseChromium = true
};

edgeOptions.AddArgument("profile-directory=Default");
edgeOptions.AddArgument(@"user-data-dir=C:\Users\xxxxxx\AppData\Local\Microsoft\Edge\User Data");

this._webDriver = new EdgeDriver(edgeDriverService, edgeOptions);
Questioner
making
Viewed
0
Yu Zhou 2021-06-08 15:35:39

You got the issue because the same user-data-dir path is configured for both instances. The user-data directory will get locked by the first instance and the second instance will fail with exception as the directory is in use. You should avoid starting Edge WebDriver instances with the same user-data-dir at the same time.

If you don't need the first Edge WebDriver instance anymore, you can close it with driver.Quit(), then you can start the second instance with the same user-data-dir path. Please remember that it's a good practice to close the WebDriver instance when you finish using it.

If you still need to use the first instance and want to start the second instance at the same time, you can create copies of the user-data-dir as User Data1, User Data2, User Data3, etc. Then you can use different user-data-dir pathes for different Edge WebDriver instances. For more detailed information, you can refer to this answer.