Fatal error: Uncaught Facebook\WebDriver\Exception\UnknownServerException: Timed out waiting for driver server to start with ChromeDriver and Selenium

Fatal error: Uncaught Facebook\WebDriver\Exception\UnknownServerException: Timed out waiting for driver server to start with ChromeDriver and Selenium

你想达到什么目的? (预期行为)

我正在尝试将 example.php 成功地转换为 运行。

你会得到什么? (实际行为)

我在日志中收到错误 500 和以下错误:

[Wed Oct 10 19:46:41.597926 2018] [:error] [pid 3951] [client 162.158.38.241:62198] 
PHP Fatal error: Uncaught Facebook\WebDriver\Exception\UnknownServerException: Timed out waiting for driver server to start.\n
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:13:22.693Z'\n
System info: host: 'raspberrypi', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'arm', os.version: '4.14.70-v7+', java.version: '1.8.0_181'\n
Driver info: driver.version: unknown in /var/www/html/selenium/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:114\nStack trace:\n
    #0 /var/www/html/selenium/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php(326): Facebook\WebDriver\Exception\WebDriverException::throwException(13, 'Timed out waiti...', Array)\n
    #1 /var/www/html/selenium/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php(126): Facebook\WebDriver\Remote\HttpCommandExecutor->execute(Object(Facebook\WebDriver\Remote\WebDriverCommand))\n
    #2 /var/www/html/selenium/index.php(21): Facebook\WebDriver\Remote\RemoteWebDriver::create('http://localhos...', Object(Facebook\WebDriver\Remote\DesiredCapabiliti in /var/www/html/selenium/vendor/facebook/webdriver/lib/Exception/WebDriverException.php on line 114

如何重现该问题? (重现步骤)

我在 Raspberry Pi Model 2 B+ 上使用 Raspbian Stretch。我将 selenium jar 文件安装在与 PHP webdriver 客户端(通过 Composer 安装)相同的目录中,并且 jar 文件似乎 运行 在端口 4444 上正常。

<?php // An example of using php-webdriver. 
// Do not forget to run composer install before and also have Selenium server started and listening on port 4444. 
namespace Facebook\WebDriver; 
use Facebook\WebDriver\Remote\DesiredCapabilities; 
use Facebook\WebDriver\Remote\RemoteWebDriver; 
require_once('vendor/autoload.php'); 

// start Chrome with 5 second timeout 
$host = 'http://localhost:4444/wd/hub'; 

// this is the default 
$capabilities = DesiredCapabilities::chrome(); 
$driver = RemoteWebDriver::create($host, $capabilities, 5000); 

// navigate to 'http://www.seleniumhq.org/' 
$driver->get('https://www.seleniumhq.org/'); 

// adding cookie 
$driver->manage()->deleteAllCookies(); 
$cookie = new Cookie('cookie_name', 'cookie_value'); 
$driver->manage()->addCookie($cookie); 
$cookies = $driver->manage()->getCookies(); 
print_r($cookies); 

// click the link 'About' 
$link = $driver->findElement( WebDriverBy::id('menu_about') ); 
$link->click(); 

// wait until the page is loaded 
$driver->wait()->until( WebDriverExpectedCondition::titleContains('About') ); 

// print the title of the current page 
echo "The title is '" . $driver->getTitle() . "'\n"; 

// print the URI of the current page 
echo "The current URI is '" . $driver->getCurrentURL() . "'\n"; 

// write 'php' in the search box 
$driver->findElement(WebDriverBy::id('q')) ->sendKeys('php') 

// fill the search 

box ->submit(); 

// submit the whole form 
// wait at most 10 seconds until at least one result is shown 

$driver->wait(10)->until( 
    WebDriverExpectedCondition::presenceOfAllElementsLocatedBy(WebDriverBy::className('gsc-result')) 
); 

// close the browser 
$driver->quit();

我相信 chromedriver 是问题的根源,尽管我不明白我是如何使用命令

正确安装它的
wget -O /tmp/chromedriver.zip https://chromedriver.storage.googleapis.com/2.42/chromedriver_linux64.zip 
&& sudo unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/;

然后在同一个 selenium 目录中再次尝试,但无济于事。

信息:

这个错误信息...

PHP Fatal error: Uncaught Facebook\WebDriver\Exception\UnknownServerException: Timed out waiting for driver server to start.

...表示 WebDriver 实例无法启动 驱动程序服务器

您的主要问题是您使用的二进制文件版本之间不兼容,如下所示:

  • 您正在使用来自 https://chromedriver.storage.googleapis.com/2.42/chromedriver_linux64.zip
  • chromedriver=2.42
  • chromedriver=2.42 的发行说明清楚地提到了以下内容:

Supports Chrome v68-70

  • 您正在使用 Chromium 浏览器 v65.0,它非常古老。

因此 Chrome驱动程序 v2.42Chrome 浏览器 v65.0

解决方案

  • Chrome驱动程序升级到当前ChromeDriver v2.42级别。
  • 保持 Chrome 版本在 Chrome v68-70[=56= 之间] 水平。 (as per ChromeDriver v2.42 release notes)
  • 清理您的项目工作区通过您的IDE重建你的项目只需要依赖。
  • 如果您的基本 Web 客户端 版本太旧,则通过 Revo Uninstaller 卸载它并安装最新的 GA 和发布版本的 Web 客户端.
  • 执行你的@Test.