World’s largest virtual agentic engineering & quality conference
You can learn automation testing with PHP with this guide which focuses on a step-by-step approach for tutorial on automation with Selenium PHP with examples! Go get the most of it!

Devansh Bhardwaj
Author

Himanshu Sheth
Reviewer
Published on: February 7, 2023
Last Updated on: July 17, 2026
It is common to use more than one programming language for automation testing. PHP is a go-to language for developers building web applications, with advantages over other languages like Java and Python. While PHP ships with fewer testing libraries than Java or Python, open source projects close that gap, and Selenium gives PHP a mature path to browser automation.
Selenium with PHP runs through php-webdriver/php-webdriver, the official, community-driven WebDriver library for PHP (formerly published as facebook/php-webdriver). In this Selenium PHP tutorial you will install the library with Composer, write your first RemoteWebDriver script, and see how PHPUnit, Codeception, and Behat fit into a real test suite.
Setting up Selenium with PHP takes three pieces: the php-webdriver/php-webdriver library, a browser driver such as ChromeDriver, and a running driver server the library talks to over the W3C WebDriver protocol. The steps below take you from an empty project to a working automation setup.
You need PHP 7.3 or later, Composer (the PHP dependency manager) available on your PATH, and Google Chrome installed locally. Composer pulls the WebDriver client from Packagist, the official PHP package registry.
Run the command below in your project root. Composer resolves the package from Packagist and writes an autoloader you include in every script.
composer require php-webdriver/webdriverChromeDriver is the browser-specific driver Selenium uses to control Chrome. Download the version that matches your Chrome build, unzip it, and confirm it runs from the command line. For Firefox you would use geckodriver instead, and the same pattern applies to other browsers.
Launch ChromeDriver directly and it listens on port 9515 by default. Your PHP script points RemoteWebDriver at http://localhost:9515. If you prefer a full Selenium Server, start it on port 4444 and use that host instead.
chromedriver --port=9515With the library installed and the driver server running, you can write a complete Selenium PHP script. The example below opens Chrome, loads a page, finds an element, types into it, clicks a button, reads the page title, and closes the session. Every flow you build later follows this same shape.
<?php
require_once 'vendor/autoload.php';
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverKeys;
// The ChromeDriver server listens on port 9515 by default
$host = 'http://localhost:9515';
// DesiredCapabilities tells the driver which browser to launch
$capabilities = DesiredCapabilities::chrome();
// RemoteWebDriver opens the session over the W3C WebDriver protocol
$driver = RemoteWebDriver::create($host, $capabilities);
// Navigate to a URL
$driver->get('https://www.google.com');
// Locate an element with WebDriverBy and type into it
$searchBox = $driver->findElement(WebDriverBy::name('q'));
$searchBox->sendKeys('TestMu AI');
$searchBox->sendKeys(WebDriverKeys::ENTER);
// Read something back from the page
echo $driver->getTitle();
// Always close the session with quit()
$driver->quit();Here is what each step does.
The script above runs against a local ChromeDriver, which is ideal for writing and debugging tests. When you need to prove the same PHP WebDriver tests work across the browsers and operating systems your users actually run, point RemoteWebDriver at TestMu AI Automation Cloud instead of localhost. It is a zero-infrastructure cloud grid that runs your existing Selenium, Cypress, Playwright, and Puppeteer scripts across 3,000+ real browser and OS combinations in parallel, capturing network logs, console logs, video, and screenshots automatically on every run, so there is no local grid to maintain.
Note: Run your Selenium PHP tests across 3,000+ real browser and OS combinations on TestMu AI. Try TestMu AI free!
Selenium drives the browser, but you still need a PHP testing framework to structure tests, run them, and report results. Three tools dominate PHP test automation, and each fits a different job.
PHPUnit is the de facto standard for unit and integration testing in PHP. It pairs cleanly with php-webdriver to drive Selenium sessions inside familiar test cases and assertions, which makes it a natural first choice for teams already writing PHPUnit tests.
Codeception builds on top of PHPUnit and adds a readable wrapper for acceptance testing. Its WebDriver module talks to Selenium directly, so you write high-level browser steps without managing the driver by hand.
Behat is the leading behavior-driven development (BDD) framework for PHP. Paired with Mink, a browser abstraction layer, Behat lets you describe scenarios in plain Gherkin language and run them against Selenium, which keeps business stakeholders close to the test suite.
| Framework | Best for | How it uses Selenium |
|---|---|---|
| PHPUnit | Unit and integration tests | Drives php-webdriver inside standard test cases and assertions |
| Codeception | Acceptance testing | Built-in WebDriver module wraps Selenium with readable steps |
| Behat with Mink | Behavior-driven development (BDD) | Gherkin scenarios run against Selenium through the Mink abstraction |
The WebDriverBy strategies these frameworks rely on are covered in the Selenium locators reference, so you can pick the right selector for each element.
You can also compare PHP against other language bindings in the Selenium Java tutorial before you commit to a stack.
For writing better and quicker Selenium automation, it is vitally important to choose the right framework for creating tests. Learn how to choose the right PHP Selenium framework.
SEE MORE →Automation Testing with Selenium PHP
This section of the Selenium PHP tutorial will help you get started with running automation tests with PHP.
This chapter will act as a step-by-step guide to help you get started with Selenium PHP, along with the prerequisites for a successful installation.
SEE MORE →In this article, you will learn how to perform Selenium automation testing using PHPUnit on a cloud-based Selenium Grid like TestMu AI. You can accelerate your tests using 3000+ real browsers and operating systems with simple commands. Check it out now!
SEE MORE →In this section of the Selenium PHP tutorial, you will learn more about the PHP testing frameworks by deep diving into the use cases for Selenium PHP.
Handling Windows in Selenium with PHP can be used for automating interactions with browser windows, tabs, and even pop-up windows. This tutorial helps you to get started testing with Selenium and PHP.
SEE MORE →Tables are a common sight in many web-based applications. And these tables are predominantly used for displaying information in a tabular format. This article takes a deep dive into the usage of tables in Selenium PHP.
SEE MORE →When using Selenium WebDriver, the PHPUnit test automation framework is one of the most popular and most used. In this particular tutorial, we will cover how to use Selenium WebDriver with the PHPUnit test framework.
SEE MORE →Handling synchronization in Selenium becomes important with dynamically loaded web elements as they may load at different time intervals. That is also where Implicit and Explicit Wait in Selenium comes into play. Check out this detailed article to learn how to handle synchronization in Selenium PHP using Implicit and Explicit Wait.
SEE MORE →There are cases where test scenarios fail unexpectedly with Selenium commands. To overcome such issues, you can execute JavaScript in Selenium through the JavaScriptExecutor interface. Check out this detailed article to learn how to execute JavaScript in Selenium PHP.
SEE MORE →Code coverage is a metric used to determine the magnitude of testing, such as how many lines of code have been executed by the test suite. It is one of the critical factors for ensuring the effectiveness of the code. This article will make you comfortable with generating code coverage reports.
SEE MORE →With Bamboo, you can build a pipeline for CI/CD, especially when the application involves cross-connectivity with different APIs and various third-party applications. It also helps your organization to become immune to risks during deployment. Check out this chapter to know in-depth.
SEE MORE →Author
Devansh Bhardwaj is a Community Evangelist at TestMu AI with 4+ years of experience in the tech industry. He has authored 30+ technical blogs on web development and automation testing and holds certifications in Automation Testing, KaneAI, Selenium, Appium, Playwright, and Cypress. Devansh has contributed to end-to-end testing of a major banking application, spanning UI, API, mobile, visual, and cross-browser testing, demonstrating hands-on expertise across modern testing workflows.
Reviewer
Himanshu Sheth is the Director of Marketing (Technical Content) at TestMu AI, with over 8 years of hands-on experience in Selenium, Cypress, and other test automation frameworks. He has authored more than 130 technical blogs for TestMu AI, covering software testing, automation strategy, and CI/CD. At TestMu AI, he leads the technical content efforts across blogs, YouTube, and social media, while closely collaborating with contributors to enhance content quality and product feedback loops. He has done his graduation with a B.E. in Computer Engineering from Mumbai University. Before TestMu AI, Himanshu led engineering teams in embedded software domains at companies like Samsung Research, Motorola, and NXP Semiconductors. He is a core member of DZone and has been a speaker at several unconferences focused on technical writing and software quality.
Did you find this page helpful?
More Related Blogs
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance