我正在尝试使用 URL 启动 chrome,浏览器启动,然后它什么也不做。

1 分钟后,我看到以下错误:

Unable to open browser with url: 'https://www.google.com' (Root cause: org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist
  (Driver info: chromedriver=2.39.562718 (9a2698cba08cf5a471a29d30c8b3e12becabb0e9),platform=Windows NT 10.0.15063 x86_64) (WARNING: The server did not provide any stacktrace information)

我的配置:
  • Chrome :66
  • ChromeBrowser:2.39.56

  • P.S 在 Firefox 中一切正常

    最佳答案

    经验法则


    这个错误信息...

    org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist
    
    ...暗示 ChromeDriver 无法启动/生成新的 WebBrowser ,即 Chrome 浏览器 session 。
    你的代码试验和所有二进制文件的版本信息会给我们一些关于出了什么问题的提示。
    然而,根据 Add --disable-dev-shm-usage to default launch flags 似乎添加参数 --disable-dev-shm-usage 将暂时解决问题。
    如果您希望启动/跨越新的 Chrome 浏览器 session ,您可以使用以下解决方案:
    System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
    ChromeOptions options = new ChromeOptions();
    options.addArguments("start-maximized"); // open Browser in maximized mode
    options.addArguments("disable-infobars"); // disabling infobars
    options.addArguments("--disable-extensions"); // disabling extensions
    options.addArguments("--disable-gpu"); // applicable to windows os only
    options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
    options.addArguments("--no-sandbox"); // Bypass OS security model
    WebDriver driver = new ChromeDriver(options);
    driver.get("https://google.com");
    

    禁用-dev-shm-usage
    根据 base_switches.cc disable-dev-shm-usage 似乎只在 Linux 操作系统上有效:
    #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
    // The /dev/shm partition is too small in certain VM environments, causing
    // Chrome to fail or crash (see http://crbug.com/715363). Use this flag to
    // work-around this issue (a temporary directory will always be used to create
    // anonymous shared memory files).
    const char kDisableDevShmUsage[] = "disable-dev-shm-usage";
    #endif
    
    在讨论 Add an option to use /tmp instead of /dev/shm David 提到:




    引用
    您可以在以下位置找到一些详细的讨论:
  • unknown error: DevToolsActivePort file doesn't exist error while executing Selenium UI test cases on ubuntu
  • Tests fail immediately with unknown error: DevToolsActivePort file doesn't exist when running Selenium grid through systemd

  • 奥特罗
    这是 Sandbox 故事的链接。

    关于google-chrome - WebDriverException : unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51211767/

    10-10 00:31
    查看更多