2017 © Pedro Pelรกez
 

library webdriver

A PHP client for Selenium WebDriver

image

facebook/webdriver

A PHP client for Selenium WebDriver

  • Saturday, June 16, 2018
  • by fosco
  • Repository
  • 181 Watchers
  • 2425 Stars
  • 11,859,725 Installations
  • PHP
  • 133 Dependents
  • 2 Suggesters
  • 601 Forks
  • 49 Open issues
  • 26 Versions
  • 8 % Grown

The README.md

php-webdriver โ€“ Selenium WebDriver bindings for PHP

Latest stable version GitHub Actions build status SauceLabs test status Total downloads, (*1)

Description

Php-webdriver library is PHP language binding for Selenium WebDriver, which allows you to control web browsers from PHP., (*2)

This library is compatible with Selenium server version 2.x, 3.x and 4.x., (*3)

The library supports modern W3C WebDriver protocol, as well as legacy JsonWireProtocol., (*4)

The concepts of this library are very similar to the "official" Java, JavaScript, .NET, Python and Ruby libraries which are developed as part of the Selenium project., (*5)

Installation

Installation is possible using Composer., (*6)

If you don't already use Composer, you can download the composer.phar binary:, (*7)

curl -sS https://getcomposer.org/installer | php

Then install the library:, (*8)

php composer.phar require php-webdriver/webdriver

Upgrade from version <1.8.0

Starting from version 1.8.0, the project has been renamed from facebook/php-webdriver to php-webdriver/webdriver., (*9)

In order to receive the new version and future updates, you need to rename it in your composer.json:, (*10)

"require": {
-    "facebook/webdriver": "(version you use)",
+    "php-webdriver/webdriver": "(version you use)",
}

and run composer update., (*11)

Getting started

1. Start server (aka. remote end)

To control a browser, you need to start a remote end (server), which will listen to the commands sent from this library and will execute them in the respective browser., (*12)

This could be Selenium standalone server, but for local development, you can send them directly to so-called "browser driver" like Chromedriver or Geckodriver., (*13)

a) Chromedriver

๐Ÿ“™ Below you will find a simple example. Make sure to read our wiki for more information on Chrome/Chromedriver., (*14)

Install the latest Chrome and Chromedriver. Make sure to have a compatible version of Chromedriver and Chrome!, (*15)

Run chromedriver binary, you can pass port argument, so that it listens on port 4444:, (*16)

chromedriver --port=4444

b) Geckodriver

๐Ÿ“™ Below you will find a simple example. Make sure to read our wiki for more information on Firefox/Geckodriver., (*17)

Install the latest Firefox and Geckodriver. Make sure to have a compatible version of Geckodriver and Firefox!, (*18)

Run geckodriver binary (it start to listen on port 4444 by default):, (*19)

geckodriver

c) Selenium standalone server

Selenium server can be useful when you need to execute multiple tests at once, when you run tests in several different browsers (like on your CI server), or when you need to distribute tests amongst several machines in grid mode (where one Selenium server acts as a hub, and others connect to it as nodes)., (*20)

Selenium server then act like a proxy and takes care of distributing commands to the respective nodes., (*21)

The latest version can be found on the Selenium download page., (*22)

๐Ÿ“™ You can find further Selenium server information in our wiki., (*23)

d) Docker

Selenium server could also be started inside Docker container - see docker-selenium project., (*24)

2. Create a Browser Session

When creating a browser session, be sure to pass the url of your running server., (*25)

For example:, (*26)

// Chromedriver (if started using --port=4444 as above)
$serverUrl = 'http://localhost:4444';
// Geckodriver
$serverUrl = 'http://localhost:4444';
// 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';

Now you can start browser of your choice:, (*27)

use Facebook\WebDriver\Remote\RemoteWebDriver;

// Chrome
$driver = RemoteWebDriver::create($serverUrl, DesiredCapabilities::chrome());
// Firefox
$driver = RemoteWebDriver::create($serverUrl, DesiredCapabilities::firefox());
// Microsoft Edge
$driver = RemoteWebDriver::create($serverUrl, DesiredCapabilities::microsoftEdge());

3. Customize Desired Capabilities

Desired capabilities define properties of the browser you are about to start., (*28)

They can be customized:, (*29)

use Facebook\WebDriver\Firefox\FirefoxOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;

$desiredCapabilities = DesiredCapabilities::firefox();

// Disable accepting SSL certificates
$desiredCapabilities->setCapability('acceptSslCerts', false);

// Add arguments via FirefoxOptions to start headless firefox
$firefoxOptions = new FirefoxOptions();
$firefoxOptions->addArguments(['-headless']);
$desiredCapabilities->setCapability(FirefoxOptions::CAPABILITY, $firefoxOptions);

$driver = RemoteWebDriver::create($serverUrl, $desiredCapabilities);

Capabilities can also be used to ๐Ÿ“™ configure a proxy server which the browser should use., (*30)

To configure browser-specific capabilities, you may use ๐Ÿ“™ ChromeOptions or ๐Ÿ“™ FirefoxOptions., (*31)

4. Control your browser

// Go to URL
$driver->get('https://en.wikipedia.org/wiki/Selenium_(software)');

// Find search element by its id, write 'PHP' inside and submit
$driver->findElement(WebDriverBy::id('searchInput')) // find search input element
    ->sendKeys('PHP') // fill the search box
    ->submit(); // submit the whole form

// Find element of 'History' item in menu by its css selector
$historyButton = $driver->findElement(
    WebDriverBy::cssSelector('#ca-history a')
);
// Read text of the element and print it to output
echo 'About to click to a button with text: ' . $historyButton->getText();

// Click the element to navigate to revision history page
$historyButton->click();

// Make sure to always call quit() at the end to terminate the browser session
$driver->quit();

See example.php for full example scenario. Visit our GitHub wiki for ๐Ÿ“™ php-webdriver command reference and further examples., (*32)

NOTE: Above snippets are not intended to be a working example by simply copy-pasting. See example.php for a working example., (*33)

Changelog

For latest changes see CHANGELOG.md file., (*34)

More information

Some basic usage example is provided in example.php file., (*35)

How-tos are provided right here in ๐Ÿ“™ our GitHub wiki., (*36)

If you don't use IDE, you may use API documentation of php-webdriver., (*37)

You may also want to check out the Selenium project docs and wiki., (*38)

Testing framework integration

To take advantage of automatized testing you may want to integrate php-webdriver to your testing framework. There are some projects already providing this:, (*39)

Support

We have a great community willing to help you!, (*40)

โ“ Do you have a question, idea or some general feedback? Visit our Discussions page. (Alternatively, you can look for many answered questions also on StackOverflow)., (*41)

๐Ÿ› Something isn't working, and you want to report a bug? Submit it here as a new issue., (*42)

๐Ÿ“™ Looking for a how-to or reference documentation? See our wiki., (*43)

Contributing โค๏ธ

We love to have your help to make php-webdriver better. See CONTRIBUTING.md for more information about contributing and developing php-webdriver., (*44)

Php-webdriver is community project - if you want to join the effort with maintaining and developing this library, the best is to look on issues marked with "help wanted" label. Let us know in the issue comments if you want to contribute and if you want any guidance, and we will be delighted to help you to prepare your pull request., (*45)

The Versions

21/06 2017

dev-licence-file

dev-licence-file https://github.com/facebook/php-webdriver

A PHP client for Selenium WebDriver

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

selenium php facebook webdriver

28/04 2017

1.4.1

1.4.1.0 https://github.com/facebook/php-webdriver

A PHP client for Selenium WebDriver

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

selenium php facebook webdriver

22/03 2017

1.4.0

1.4.0.0 https://github.com/facebook/php-webdriver

A PHP client for Selenium WebDriver

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

selenium php facebook webdriver

13/01 2017
14/10 2016

1.2.0

1.2.0.0 https://github.com/facebook/php-webdriver

A PHP client for WebDriver

  Sources   Download

Apache-2.0

The Requires

  • php ^5.5 || ~7.0
  • ext-curl *

 

The Development Requires

selenium php facebook webdriver

10/08 2016

1.1.3

1.1.3.0 https://github.com/facebook/php-webdriver

A PHP client for WebDriver

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.19
  • ext-curl *

 

The Development Requires

selenium php facebook webdriver

04/06 2016

1.1.2

1.1.2.0 https://github.com/facebook/php-webdriver

A PHP client for WebDriver

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.19
  • ext-curl *

 

The Development Requires

selenium php facebook webdriver

31/12 2015

1.1.1

1.1.1.0 https://github.com/facebook/php-webdriver

A PHP client for WebDriver

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.19

 

The Development Requires

selenium php facebook webdriver

08/12 2015

1.1.0

1.1.0.0 https://github.com/facebook/php-webdriver

A PHP client for WebDriver

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.19

 

The Development Requires

selenium php facebook webdriver

03/11 2015

1.0.4

1.0.4.0 https://github.com/facebook/php-webdriver

A PHP client for WebDriver

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.19

 

The Development Requires

selenium php facebook webdriver

01/11 2015

1.0.3

1.0.3.0 https://github.com/facebook/php-webdriver

A PHP client for WebDriver

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.19

 

The Development Requires

selenium php facebook webdriver

12/08 2015

1.0.2

1.0.2.0 https://github.com/facebook/php-webdriver

A PHP client for WebDriver

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.19

 

The Development Requires

selenium php facebook webdriver

16/07 2015

1.0.1

1.0.1.0 https://github.com/facebook/php-webdriver

A PHP client for WebDriver

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.19

 

The Development Requires

selenium php facebook webdriver

09/06 2015

dev-master

9999999-dev https://github.com/facebook/php-webdriver

A php client for WebDriver

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.19

 

The Development Requires

selenium php facebook webdriver

09/06 2015

1.0.0

1.0.0.0 https://github.com/facebook/php-webdriver

A PHP client for WebDriver

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.19

 

The Development Requires

selenium php facebook webdriver

09/02 2015

v0.6.0

0.6.0.0 https://github.com/facebook/php-webdriver

A php client for WebDriver

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.19

 

The Development Requires

selenium php facebook webdriver

05/11 2014

v0.5.1

0.5.1.0 https://github.com/facebook/php-webdriver

A php client for WebDriver

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.19

 

The Development Requires

selenium php facebook webdriver

28/10 2014

v0.5

0.5.0.0 https://github.com/facebook/php-webdriver

A php client for WebDriver

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.19

 

The Development Requires

selenium php facebook webdriver

21/02 2014

v0.4

0.4.0.0 https://github.com/facebook/php-webdriver

A php client for WebDriver

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.19

 

The Development Requires

selenium php facebook webdriver

27/11 2013

v0.3

0.3.0.0 https://github.com/facebook/php-webdriver

A php client for WebDriver

  Sources   Download

Apache-2.0

The Requires

 

selenium php facebook webdriver

15/10 2013

v0.2.1

0.2.1.0 https://github.com/facebook/php-webdriver

A php client for WebDriver

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4.20

 

10/10 2013

v0.2

0.2.0.0 https://github.com/facebook/php-webdriver

A php client for WebDriver

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4.0

 

10/09 2013

v0.1

0.1.0.0 https://github.com/facebook/php-webdriver

A php client for WebDriver

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0