Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Getting Started With Selenium Testing using PHP

We all know that Selenium can be used to perform automated tests. Some of us may even already have a perfectly working testing solution that uses it. However, if you're like me, then you just never really got round to it because getting the tool working and writing the tests was such a pain in the butt. This tutorial aims to address that by giving instructions on using Selenium from scratch, which includes downloading Selenium and the necessary browser driver before then writing and running a test that was written in PHP (which I believe is much easier than using Java).


Below is a video of me performing this tutorial myself on a freshly installed Ubuntu 16.04 desktop.


Download the latest selenium standalone server from this page. At the time of writing this tutorial, it is version 3.8.1


For the next step, You may require installing some php extensions

sudo apt-get install php7.2-zip php7.2-curl -y

Install composer if you haven't got it already. Then use it tonstall the php webdriver from facebook.

composer require facebook/webdriver

Run the selenium server with passthrough disabled. You may need to install Java if you haven't got it already.

java -jar selenium-server-standalone-3.141.59.jar -enablePassThrough false

Get the latest chrome driver from here.

sudo mv -i chromedriver /usr/bin/.

Get the gecko driver from the releases page for Firefox.

tar --extract --gzip --file gecko*
sudo mv -i geckodriver /usr/bin/.

require_once(__DIR__ . '/vendor/autoload.php');

$host = 'http://localhost:4444/wd/hub'; // this is the default
$USE_FIREFOX = true; // if false, will use chrome.

    $driver = Facebook\WebDriver\Remote\RemoteWebDriver::create(
    $driver = Facebook\WebDriver\Remote\RemoteWebDriver::create(


# enter text into the search field
$driver->findElement(Facebook\WebDriver\WebDriverBy::id('lst-ib'))->sendKeys('programster selenium');

# Click the search button

References / Resources

Last updated: 26th February 2021
First published: 16th August 2018