thin php client for webdriver.
Pull request Compare This branch is 125 commits behind Element-34:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

php-webdriver -- A very thin wrapper of WebDriver


This client aims to be as thin as possible, abusing the dynamic nature of PHP to allow almost all API calls to be a direct transformation of what is defined in the WebDriver protocol itself.

Most clients require you to first read the protocol to see what's possible, then study the client itself to see how to call it. This hopes to eliminate the latter step, and invites you to rely almost exclusively on

Each command is just the name of a function call, and each additional path is just another chained function call. The function parameter is then either an array() if the command takes JSON parameters, or an individual primitive if it takes a URL parameter.

The function's return value is exactly what is returned from the server as part of the protocol definition. If an error is returned, the function will throw the appropriate WebDriverException instance.

Note - This is a maintained clone of with following differences

  • Class names being slightly different for packaging within PEAR
  • Implementation of WebDriverWait


  • This driver has been packaged for distribution via PEAR. So...

    pear channel-discover
    pear install -f element-34/PHPWebDriver
  • All you need as the server for this client is the selenium-server-standalone-#.jar file provided here:

  • Download and run that file, replacing # with the current server version.

    java -jar selenium-server-standalone-#.jar
  • Then when you create a session, be sure to pass the url to where your server is running.

    // This would be the url of the host running the server-standalone.jar
    $wd_host = 'http://localhost:4444/wd/hub';
    $web_driver = new PHPWebDriver_WebDriver($wd_host);
    // First param to session() is the 'browserName' (default = 'firefox')
    // Second param is a JSON object of additional 'desiredCapabilities'
    // POST /session
    $session = $web_driver->session('firefox');
  • Valid browser strings

    • firefox
    • chrome
    • ie
    • internet explorer
    • opera
    • htmlunit
    • htmlunitjs
    • iphone
    • ipad
    • android


Note that all of these match the Protocol exactly

  • Move to a specific spot on the screen

    // POST /session/:sessionId/moveto
    $session->moveto(array('xoffset' => 3, 'yoffset' => 300));
  • Get the current url

    // GET /session/:sessionId/url
  • Get a list of window handles for all open windows

    // GET /session/:sessionId/window_handles
  • Accept the currently displayed alert dialog

    // POST /session/:sessionId/accept_alert
  • Doubleclick an element on a touch screen

    // POST session/:sessionId/touch/doubleclick
    $session->touch()->doubleclick(array('element' => $element->getID())
  • Check if two elements are equal

    // GET /session/:sessionId/element/:id/equals/:other
  • Get value of a css property on element

    // GET /session/:sessionId/element/:id/css/:propertyName

'GET', 'POST', or 'DELETE' to the same command examples

When you can do multiple http methods for the same command, call the command directly for the 'GET', and prepend the http method for the 'POST' or 'DELETE'.

  • Set landscape orientation with 'POST'

    // POST /session/:sessionId/orientation
    $session->postOrientation(array('orientation' => 'LANDSCAPE'));
  • Get landscape orientation with normal 'GET'

    // GET /session/:sessionId/orientation
  • Set size of window that has $window_handle with 'POST'

    // If excluded, $window_handle defaults to 'current'
    // POST /session/:sessionId/window/:windowHandle/size
      ->postSize(array('width' => 10, 'height' => 10));
  • Get current window size with 'GET'

    // GET /session/:sessionId/window/:windowHandle/size

Some unavoidable exceptions to direct protocol translation.

  • Opening pages

    // POST /session/:sessionId/url
  • Dealing with the session

    // DELETE /session/:sessionId
    // GET /session/:sessionId
  • To find elements

    // POST /session/:sessionId/element
    $element = $session->element($using, $value);
    // POST /session/:sessionId/elements
    $session->elements($using, $value);
    // POST /session/:sessionId/element/:id/element
    $element->element($using, $value);
    // POST /session/:sessionId/element/:id/elements
    $element->elements($using, $value);
  • To get the active element

    // POST /session/:sessionId/element/active
  • To manipulate cookies

    // GET /session/:sessionId/cookie
    // GET /session/:sessionId/cookie
    // POST /session/:sessionId/cookie
    // $cookie_array mandatory fields
    // - name: string
    // - vale: string
    // $cookie_array optional fields
    // - path: string
    // - domain: string
    // - secure: boolean
    // - expiry: number (seconds since epoch)
    // DELETE /session/:sessionId/cookie
    // DELETE /session/:sessionId/cookie/:name
  • To manipulate windows

    // POST /session/:sessionId/window
    // DELETE /session/:sessionId/window


The until function will fire until it returns something PHP considers True

  • To wait for an element that you want to use then

    $w = new PHPWebDriver_WebDriverWait($session);
    $e = $w->until(
            function($session) {
              return $session->element("id", "overlayPanelProfileovolp-pad");
  • To wait for an element's presence

     $w = new PHPWebDriver_WebDriverWait($session);
        function($session) {
          return count($session->elements("id", "overlayPanelProfileovolp-pad"));


  • To configure implicit waits (in seconds)

  • To disable implicit waits

  • How long to wait for an execute or execute_async to (in seconds)

  • How long to wait page loads to complete (in seconds)

  • How to set the above timeouts directly. Don't do this unless you really need ms granularity

    $this->$session->setTimeouts(array('type' => 'implicit', 'ms' => 5));
    $this->$session->setTimeouts(array('type' => 'script', 'ms' => 5));
    $this->$session->setTimeouts(array('type' => 'page load', 'ms' => 5));

Interacting with elements

  • Sending characters per the protocol (yuck)

    $e1 = $this->session->element("id", "some id");
    $e1->value(array("value" => array("pumpkins")));
  • Sending characters a little nicer

    $e2 = $this->session->element("id", "some id");
  • Sending a 'special' character (see list at

    $e3 = $this->session->element("id", "some id");
  • Advancing the page by using the space key

    $e4 = $this->session->element("tag name", "body");


  • Http proxying

    $server = 'http://localhost:4444/wd/hub';
    $driver = new PHPWebDriver_WebDriver($server);
    $desired_capabilities = array();
    $proxy = new PHPWebDriver_WebDriverProxy();
    $proxy->httpProxy = ';
    $session = $driver->session('firefox', $desired_capabilities);


  • Screenshots are returned as base64 strings from the server

    $img = $session->screenshot();
    $data = base64_decode($img);
    $file = '';
    $success = file_put_contents($file, $data);


  • Change focus to another frame

    // find your iframe
    $iframe = self::$session->element("css selector", "iframe");
    // switch context to it
    // interact
    $ps = self::$session->elements("css selector", "p");
    $this->assertEquals(count($ps), 6);
    // switch back