'Selenium + facebook php-webdriver: Unable to create new service: ChromeDriverService

I'm trying to set up Selenium with the facebook php-webdriver. This is what I've done:

  • Ran composer require facebook/webdriver to install the package
  • Started the selenium server on port 4444 (default)
  • Downloaded the latest 32-bit chromedriver from enter link description here (No separate 64bit available)
  • Copied the chromedriver.exe to the project folder (don't know if this is necessary)
  • Stated chromedriver. It runs on port 9515 by default.
  • Ran the script to open a browser window in chrome.

In my script below, I get an error on the third line

$host = 'http://localhost:4444/wd/hub'; // this is the default
$capabilities = DesiredCapabilities::chrome();
$driver = RemoteWebDriver::create($host, $capabilities);

The error:

Fatal error: Uncaught Facebook\WebDriver\Exception\SessionNotCreatedException: Unable to create new service: ChromeDriverService Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:33:15.31Z' System info: host: 'WINCOM', ip: '192.168.0.10', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '9.0.1' Driver info: driver.version: unknown in C:\xampp\htdocs\xampp\testnew\vendor\facebook\webdriver\lib\Exception\WebDriverException.php:154 Stack trace: #0 C:\xampp\htdocs\xampp\testnew\vendor\facebook\webdriver\lib\Remote\HttpCommandExecutor.php(320): Facebook\WebDriver\Exception\WebDriverException::throwException(33, 'Unable to creat...', Array) #1 C:\xampp\htdocs\xampp\testnew\vendor\facebook\webdriver\lib\Remote\RemoteWebDriver.php(126): Facebook\WebDriver\Remote\HttpCommandExecutor->execute(Object(Facebook\WebDriver\Remote\WebDriverCommand)) #2 C:\xampp\htdocs\xampp\testnew\test.php(11): Facebook\WebDriver\Remote\RemoteWebDriver::create('http://localhos...', Object(Facebook\WebDriver in C:\xampp\htdocs\xampp\testnew\vendor\facebook\webdriver\lib\Exception\WebDriverException.php on line 154

In the Selenium terminal, I see this message:

14:18:08.607 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.remote.server.ServicedSession$Factory (provider:org.openqa.selenium.chrome.ChromeDriverService)

Can anyone direct me on how to solve this. I've looked everywhere, but nothing seems to work.

Thanks



Solution 1:[1]

I had exactly the same problem. It seems you should put the chrome web driver executable and your script in the same folder.

Solution 2:[2]

Running geckodriver with root user I got the same problem. Running geckodriver with same user than php scripts, it started to work. You can try running both with unprivileged user.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Masato Nagashima
Solution 2 Daniel