当我在 Selenium 中创建一个新的 chrome 驱动程序时,Google Chrome 已经在运行并且我正在引用用户设置/数据(通过 user-data-dir
)。将打开一个新的 Chrome 窗口,但我的应用程序将挂起。 ChromeDriver 控制台将每秒显示以下错误:DevTools Request: 127.0.0.1:12585/json/version。 DevTools 请求失败
实例化驱动程序的代码:
ChromeDriverService driverService = ChromeDriverService.CreateDefaultService();
//driverService.HideCommandPromptWindow = true;
driverService.EnableVerboseLogging = true;
string path = Environment.ExpandEnvironmentVariables("%LOCALAPPDATA%\\Google\\Chrome\\User Data");
ChromeOptions options = new ChromeOptions();
options.AddArguments("user-data-dir=" + path);
options.AddArguments("--start-maximized");
options.AddArguments("--disable-extensions");
IWebDriver driver = new ChromeDriver(driverService, options);
如果我不尝试加载用户设置/数据,这在任何情况下都可以正常工作。如果我尝试加载用户设置/数据,它只会在设备上没有运行 Chrome 实例的情况下起作用。
版本:
- Selenium v 2.47.0
- ChromeDriver v 2.16.333243
- Chrome v44.0.2403
我该怎么做才能解决这个问题?
最佳答案
如果有人像我一样在寻找答案;
https://bugs.chromium.org/p/chromedriver/issues/detail?id=2443
This behavior is by design. Two instances of Chrome can't use the same user-data-dir at the same time. Otherwise they would try to update the same set of files and cause corruptions. So if an instance is already running, attempting to start another instance using the same user-data-dir will cause the second instance to ask the first instance to open a new window, and then the second instance exits.
关于c# - Selenium:实例化时为 "DevTools Request: 127.0.0.1:12583/json/version failed",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31841763/