我试图用一个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

又及,在Firefox中一切都很好


当前回答

在我的例子中,当我试图使用我的默认用户配置文件时,它发生了:

...
options.addArguments("user-data-dir=D:\\MyHomeDirectory\\Google\\Chrome\\User Data");
...

这触发chrome重用已经在后台运行的进程,以这种方式,由chromedriver.exe启动的进程简单地结束。

解决方法:关闭所有在后台运行的chrome.exe进程。

其他回答

我也有同样的错误,我发现原因是因为我的电脑磁盘已满。删除了一些不必要的文件后,错误就消失了。

我用Jenkins在Ubuntu 18 LTS linux上运行selenium测试。我有这个错误,直到我像这样添加了参数'headless'(以及其他一些参数):

ChromeOptions options = new ChromeOptions();
options.addArguments("headless"); // headless -> no browser window. needed for jenkins
options.addArguments("disable-infobars"); // disabling infobars
options.addArguments("--disable-extensions"); // disabling extensions
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("--no-sandbox"); // Bypass OS security model
ChromeDriver driver = new ChromeDriver(options);

driver.get("www.google.com");

核心的答案 正确的解决方案:不使用root用户运行Chrome二进制 更多细节请参考另一个帖子的回答:未知错误:DevToolsActivePort文件不存在

I started seeing this problem on Monday 2018-06-04. Our tests run each weekday. It appears that the only thing that changed was the google-chrome version (which had been updated to current) JVM and Selenium were recent versions on Linux box ( Java 1.8.0_151, selenium 3.12.0, google-chrome 67.0.3396.62, and xvfb-run). Specifically adding the arguments "--no-sandbox" and "--disable-dev-shm-usage" stopped the error. I'll look into these issues to find more info about the effect, and other questions as in what triggered google-chrome to update.

ChromeOptions options = new ChromeOptions();
        ...
        options.addArguments("--no-sandbox");
        options.addArguments("--disable-dev-shm-usage");

我被这个问题困扰了很长一段时间,最后通过添加一个额外的选项来解决它:

options.addArguments(”——crash-dumps-dir = / tmp”)