我试图用一个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中一切都很好


当前回答

更新conf.js中的功能

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['todo-spec.js'],
  capabilities: {
    browserName: 'chrome',
    chromeOptions: {
      args: ['--disable-gpu', '--no-sandbox', '--disable-extensions', '--disable-dev-shm-usage']
    }
  },

};

其他回答

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

我的问题是php-webdriver中的一个bug。我的代码是:

$chromeOptions = new ChromeOptions();
$chromeOptions->addArguments([
    '--headless',
    '--no-sandbox',
    '--disable-gpu',
    '--disable-dev-shm-usage',
    '--no-proxy-server'
]);
$chromeOptions->setExperimentalOption('detach', true);
$capabilities = DesiredCapabilities::chrome();
$capabilities->setCapability(
    ChromeOptions::CAPABILITY,
    $chromeOptions
);

如你所见,一切都符合其他可能的原因。

但实际上这些功能并没有传递给chromedriver。我不得不改变设置chrome选项功能:

$capabilities->setCapability(
    ChromeOptions::CAPABILITY_W3C, // <<< Have to use W3C capabilities with recent versions of Chromedriver.
    $chromeOptions->toArray() // <<<<< bug in php-webdriver 1.9, object not getting serialized automatically like with the deprecated capability ChromeOptions::CAPABILITY
);

我的设置是:

$ chromedriver --version
ChromeDriver 79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-heads/3945@{#614})
$ java -jar selenium-server-standalone-3.141.59.jar --version
Selenium server version: 3.141.59, revision: e82be7d358

做了一个bug报告和一个PR来修复php-webdriver中的这个bug

https://github.com/php-webdriver/php-webdriver/issues/849

在我的例子中,我在Kubernetes环境中不能使用默认的TMPDIR,因为它会用垃圾填满临时目录。

所以我用这个来使用不同的tmpdir:

driver = new ChromeDriver(new ChromeDriverService.Builder()
                    .withEnvironment(ImmutableMap.of("TMPDIR", customTmpPath))
                    .build(), options);

但现在我把所有东西都升级到最新版本,这似乎不再管用了。我需要找到一种新的方法来做这件事。

日期9/16/2021

在docker托管的ubuntu容器中使用python在本地运行chrome和selenium,一切都很好。当试图运行从Jenkins上面的错误返回WebDriverException:未知错误:DevToolsActivePort

环境:

-Ubuntu21.04在docker容器内,支持RDP访问。

chrome版本:93

解决方案: 在启动浏览器的python文件中,我必须使用以下行设置DISPLAY环境变量:

import os

os.environ['DISPLAY'] = ':10.0'
#DISPLAY_VAR = os.environ.get('DISPLAY')
#print("DISPLAY_VAR:", DISPLAY_VAR)

我有同样的问题,但在我的情况下,chrome之前安装在用户临时文件夹,之后被重新安装到程序文件。所以这里提供的任何解决方案都帮不了我。但是如果提供了chrome.exe的路径就可以了:

chromeOptions.setBinary("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");

我希望这能帮助到一些人=)