c# - Selenium:实例化时为 "DevTools Request: 127.0.0.1:12583/json/version failed"

标签 c# google-chrome selenium selenium-chromedriver

当我在 Selenium 中创建一个新的 chrome 驱动程序时,Google Chrome 已经在运行并且我正在引用用户设置/数据(通过 user-data-dir)。将打开一个新的 Chrome 窗口,但我的应用程序将挂起。 ChromeDriver 控制台将每秒显示以下错误:DevTools Request: 127.0.0.1:12585/json/version。 DevTools 请求失败

截图:enter image description here

实例化驱动程序的代码:

        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/

相关文章:

java - 切换到新选项卡的元素 - selenium

java - 如何从 CSV 中读取行以在多线程中使用

java - 检查 Selenium Webdriver (Java) 中的 Bootstrap 下拉列表值

java - 使用 Gradle maxParallelForks 属性执行并行测试

c# - 在 Winforms 自定义 UserControl 上启用设计界面

C# tcp 套接字如何判断正在发送的对象类型?

javascript - 为什么我的 Contenteditable 插入符在 Chrome 中跳到最后?

c# - ASP.NET MVC 和 NHibernate - 使用属性而不是 XML

c# - 将选择设置为 View 框

css - 无法通过 flask 中的CSS更改背景图像大小