Check if element exists Selenium in php

Below example shows how to check if specific element exists on the web page or not.
class TestSize extends PHPUnit_Framework_TestCase {

protected $webDriver;

public function setUp()
$capabilities = array(WebDriverCapabilityType::BROWSER_NAME => ‘chrome’);
$this->webDriver = RemoteWebDriver::create(‘https://localhost:4444/wd/hub’, $capabilities);

public function testSize()

$elements = $this->webDriver->findElements(WebDriverBy::id(‘fn’));

if (sizeof($elements)==0)
 Element with id fn not found”);
 Element with id fn found”);


public function tearDown()
//Quit the driver

Web development and Automation testing

solutions delivered!!