Working with multiple frames in Selenium in php

Below example explains how to switch to frame in Selenium in PHP. In below example, we are switching to frame with name “g” and grabbing the portion of page source inside that frame. Then we have switched to main window document using defaultContent() method.
class MyTest 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 testFrames()

//Switch to frame with name “g”

echo (“
Portion of HTML Source of Frame -> ” . substr($this->webDriver->getPageSource(), 0, 300));

echo (“


echo (“
Portion of HTML Source of Main window -> ” . substr($this->webDriver->getPageSource(), 0, 300));


public function tearDown()
//Quit the driver

Web development and Automation testing

solutions delivered!!