【问题标题】:Can't start headless chrome无法启动无头 chrome
【发布时间】:2018-12-05 11:34:29
【问题描述】:

我尝试以编程方式使用 Laravel Dusk。当我尝试以下代码时:

use Symfony\Component\Process\Process;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;

$driver = realpath(base_path() . '/vendor/laravel/dusk/bin/chromedriver-linux');

$process = new Process(
    array_merge([realpath($driver)], []), null, ['DISPLAY' => ':0']
);

$process->start();

$options = (new ChromeOptions)->addArguments([]);
$capabilities = DesiredCapabilities::chrome()->setCapability(
    ChromeOptions::CAPABILITY, $options
);

return RemoteWebDriver::create(
    'http://localhost:9515', $capabilities, 5000, 10000
);

我收到此错误。我尝试使用 FacebookWebDriver 作为独立组件,也得到了相同的结果:

Curl error thrown for http POST to /session with params: 
{"desiredCapabilities": 
{"browserName":"chrome","platform":"ANY","chromeOptions": 
{"binary":""}}} Operation timed out after 10001 milliseconds with 0 bytes received

有问题的端口未在使用中。无法找出代码有什么问题。

【问题讨论】:

  • 与直接 localhost ip 相同的错误
  • vendor/laravel/dusk/bin/chromedriver-linux --v 的结果是什么?您使用的是哪个版本的 Chrome?
  • 抱歉回复晚了。我已经通过将 Selenium Standalone jar 和 chromedriver-linux 可执行文件放在同一目录中解决了这个问题

标签: php laravel selenium-chromedriver laravel-dusk


【解决方案1】:

通过将 Selenium Standalone jar 和 chromedriver 放在同一目录中解决了这个问题。确保在路径中包含文件夹目录。可能对其他人有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-25
    相关资源
    最近更新 更多