致命错误:找不到Facebook \ WebDriver \ Exception \ UnknownServerException:超时,等待驱动程序服务器从ChromeDriver和Selenium启动

时间:2018-10-11 12:39:25

标签: php selenium google-chrome raspberry-pi selenium-chromedriver

您要达到什么目标? (预期的行为)

我正在尝试使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。我将硒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/;

,然后再次在相同的硒目录中,无济于事。

信息:

  • Php-webdriver版本:1.6.0
  • PHP版本:7.0.30-0 + deb9u1
  • 硒服务器版本:3.14.0
  • 操作系统:Raspbian Stretch
  • 使用的浏览器+版本:Chromium浏览器,版本65.0.3325.181-0 + rpt4

1 个答案:

答案 0 :(得分:2)

此错误消息...

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的发行说明中明确提到以下内容:
  

支持 Chrome v68-70

  • 您使用的是非常古老的 Chromium Browser v65.0

因此 ChromeDriver v2.42 Chrome浏览器v65.0

之间存在明显的不匹配

解决方案

  • ChromeDriver 升级到当前的ChromeDriver v2.42级别。
  • Chrome 版本保持在 Chrome v68-70 级别之间。 (as per ChromeDriver v2.42 release notes
  • 通过您的 IDE
  • 清理您的项目工作区重建您的项目,并且仅具有必需的依赖项。
  • 如果您的基本 Web客户端版本过旧,请通过Revo Uninstaller进行卸载,并安装最新版本的 Web客户端。 li>
  • 执行您的@Test