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


当前回答

在尝试在Linux服务器上运行selenium时遇到了同样的问题,尝试降级你的chrome版本,它对我有用吗

从这里选择版本

http://170.210.201.179/linux/chrome/deb/pool/main/g/google-chrome-stable/

其他回答

也有同样的问题。我正在谷歌云虚拟机上运行selenium脚本。

options.addArguments("--headless");

上面这句话解决了我的问题。我删除了其他可选参数。我认为其他答案中提到的其余代码行对解决云VM上的问题没有任何影响。

TL;DR:如果你使用VirtualBox共享文件夹,不要在那里创建Chrome配置文件!


我在Debian 10下遇到了这个错误,但在Ubuntu 18.04下没有发生。

在我的Selenium测试中,我想安装一个扩展,并使用以下Chrome选项:

chromeOptions.addArguments(
  `load-extension=${this.extensionDir}`,
  `user-data-dir=${this.profileDir}`,
  `disable-gpu`,
  `no-sandbox`,
  `disable-setuid-sandbox`,
  `disable-dev-shm-usage`,
);

问题是,我试图在一个非标准目录下创建一个Chrome配置文件,这是VirtualBox共享文件夹的一部分。尽管使用的是完全相同版本的Chrome和Chromedriver,但在Debian下却无法运行。

解决方案是在其他地方选择一个概要目录(例如~/chrome-profile)。

老问题,但类似的问题几乎把我逼疯了,所以分享我的解决方案。其他的建议都不能解决我的问题。

当我将Docker镜像Chrome从旧版本更新到Chrome 86时,我得到了这个错误。我的设置是不相同的,但我们实例化Chrome通过一个硒webdriver。

解决方案是将选项传递为goog:chromeOptions哈希而不是chromeOptions哈希。我真的不知道这是一个硒,Chrome, Chromedriver,或其他更新,但也许某些可怜的灵魂会在未来的这个答案中找到安慰。

我的问题是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

我在Docker容器中通过Behat/Mink和Selenium运行Chrome时也遇到了同样的问题。经过一番折腾,我得出了如下结论。Yml提供上面提到的开关。请注意,要使它成功运行,所有这些都是必需的。

default:
    extensions:
        Behat\MinkExtension:
            base_url: https://my.app/
            default_session: selenium2
            selenium2:
                browser: chrome
                capabilities:
                    extra_capabilities:
                        chromeOptions:
                            args:
                                - "headless"
                                - "no-sandbox"
                                - "disable-dev-shm-usage"