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


当前回答

日期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)

其他回答

我通过安装yum -y install gtk3-devel gtk3-dev -docs”来解决这个问题,它可以正常工作

我的工作环境是:

Selenium Version 3.12.0
ChromeDriver Version v2.40
Chrome 68 level

之前:

后:

更新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

更新:

我能够通过这个问题,现在我能够访问chrome所需的url。

对所提供解决方案的尝试结果:

我尝试了上面提供的所有设置,但我无法解决这个问题

关于问题的解释:

根据我的观察,DevToolsActivePort文件不存在的原因是chrome无法在scoped_dirXXXXX文件夹中找到它的引用。

为解决该问题所采取的步骤

我已经杀死了所有的chrome进程和chrome驱动程序进程。 添加下面的代码来调用chrome System.setProperty(“webdriver.chrome.driver”、“pathto \ \ chromedriver.exe”); ChromeOptions选项=新的ChromeOptions(); 选项。setExperimentalOption(“useAutomationExtension”,假); WebDriver驱动=新的ChromeDriver(选项); driver.get (url);

使用上述步骤,我能够解决这个问题。

谢谢你的回答。

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