php-webdriver/webdriver
PHP bindings for Selenium WebDriver. Drive real browsers from PHP via W3C WebDriver (and legacy JsonWireProtocol), compatible with Selenium 2–4. Install via Composer and connect to Selenium Server or other remote ends for automation/testing.
Start by installing via Composer: composer require php-webdriver/webdriver. Ensure you have a WebDriver server running — for local dev, download and run chromedriver or geckodriver on port 4444, or use Selenium Standalone Server (v4+ uses / endpoint, v3 uses /wd/hub). Then, create a session: RemoteWebDriver::create('http://localhost:4444', DesiredCapabilities::chrome()). Your first task is likely loading a page and interacting with elements: $driver->get('https://example.com'); $driver->findElement(WebDriverBy::id('submit'))?->click();. Always call $driver->quit() to clean up.
Use RemoteWebDriver::create() with DesiredCapabilities and browser-specific options (e.g., ChromeOptions, FirefoxOptions) to configure headless mode, arguments, extensions, and preferences. For tests, wrap interactions in PHPUnit using try/finally for cleanup, or leverage integrations like Laravel Dusk (high-level DSL), Symfony Panther (based on php-webdriver), Steward (parallelized PHPUnit), or Codeception (WebDriver module). Use WebDriverWait for reliable synchronization instead of sleep(): (new WebDriverWait($driver, 10))->until(ExpectedConditions::visibilityOfElementLocated(WebDriverBy::id('result'))). Organize page interactions into Page Object classes to improve maintainability and reusability.
acceptSslCerts capability or use browser options to ignore cert errors — don’t rely on deprecated SSL flags.createBySessionID() requires capabilities to be explicitly passed now; isDisplayed() may fail if no capabilities are set — ensure compatibility when reusing sessions.int|float|null; invalid types cause protocol errors. Always use null for implicit timeout if unset.findElement() throws NoSuchElementException; findElements() returns an empty array — handle both explicitly to avoid silent failures.sendKeys(realpath($path)) on <input type="file">; the W3C-compliant upload endpoint was fixed in v1.16.0.facebook/php-webdriver, update composer.json to php-webdriver/webdriver and replace namespace Facebook\WebDriver → Facebook\WebDriver (namespace unchanged in 1.x, but package name is critical).--enable-automation or driver flags; Geckodriver requires explicit enabling (as of v1.15.2 test setup).How can I help you explore Laravel packages today?