5

Google Chrome 79.0.3945.130
ChromeDriver 79.0.3945.36
selenium-server-4.0.0-alpha-4.jar
Newest code from the php-webdriver GitHub as of 1/22/2020

I am starting the Selenium server in standalone mode on localhost using Xfvb as such:

$ Xvfb :99 -screen 5 1920x1080x8 &
$ export DISPLAY=:99
$ java -Dwebdriver.chrome.driver="./chromedriver" -jar selenium-server-4.0.0-alpha-4.jar standalone

I then have a test helper class which starts things up in the PHP code:

    1 final public static function createWebDriver() {
    2   $options = new ChromeOptions();
    3   $options->addArguments(array('--window-size=1920,1080'));
    4   $caps= DesiredCapabilities::chrome();
    5   $caps->setCapability(ChromeOptions::CAPABILITY, $options);
    6   $driver = RemoteWebDriver::create('http://localhost:4444/wd/hub', $caps);
    7   $driver->manage()->window()->maximize();
    8   return $driver;
    9}

When I run a test and call the RemoteWebDriver::create() function, it throws an exception:

Facebook\WebDriver\Exception\UnknownCommandException: Unable to find handler for (POST) /wd/hub/session /home/me/UnitTest/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:137 /home/me/UnitTest/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:380 /home/me/UnitTest/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:136 /var/www/html/project/core/functions/SeleniumTestHelper.php:6

The line that's the issue is:
$driver = RemoteWebDriver::create('http://localhost:4444/wd/hub', $caps);

I confirm with netstat that I am listening on all addresses to port 4444. I cannot find a directory called "hub" on my machine. I'm not sure why this isn't working and it would seem there is not any more info than this exception for me to go off of.

Joey
  • 352
  • 1
  • 4
  • 9
  • I get the same error when i deploy a cluster with this : https://github.com/SeleniumHQ/docker-selenium/blob/trunk/k8s-deployment-full-grid.yaml – djangofan Dec 08 '20 at 22:45

2 Answers2

6

andrewnichols helped me out on the GitHub! Here is his response. Many thanks to him. I will share the response here for anyone who comes across this question.

Hi @JoeyofBladez,

Selenium 4 changes the URL. It's no longer behind /wd/hub. The error is correct. It does not know what /wd/hub/session means. The new URL is http://localhost:4444 which would make the new session URL http://localhost:4444/session.

You can view the status at http://localhost:4444/status

Joey
  • 352
  • 1
  • 4
  • 9
1

We extended php-webdriver README to make it clear which URL of Selenium server you should use for which version.

ChromeDriver

If you start Chromedriver on command line with no options:

$ chromedriver

Then you use:

$serverUrl = 'http://localhost:9515';

$driver = RemoteWebDriver::create($serverUrl, DesiredCapabilities::chrome());

You can however specify port by yourself:

$ chromedriver --port=4444

Then you use:

$serverUrl = 'http://localhost:4444';

GeckoDriver

$ geckodriver

Use in your script:

$serverUrl = 'http://localhost:4444';
$driver = RemoteWebDriver::create($serverUrl, DesiredCapabilities::firefox());

Selenium standalone server

// selenium-server-standalone-#.jar (version 2.x or 3.x)
$serverUrl = 'http://localhost:4444/wd/hub';

// selenium-server-standalone-#.jar (version 4.x)
$serverUrl = 'http://localhost:4444';

$driver = RemoteWebDriver::create($serverUrl, DesiredCapabilities::chrome()); // or other browser
Ondrej Machulda
  • 998
  • 1
  • 12
  • 24