Selenium + PHP
Introduction to Selenium Webdriver Installation and Environment set up Chrome Chrome with options Chrome in Mobile Emulation IE Firefox Element identification methods Assertions in Selenium in PHP Interacting with elements in Selenium in PHP Basic Browser window automation Sending keys in Selenium in PHP Synchronization in Selenium Check if Element exists Working with Tables using Selenium Performing advanced actions using Selenium in PHP Executing JavaScript in Selenium in PHP Working with multiple Browser Windows or tabs Working with multiple frames Handling alerts Taking a screenshot in selenium Integration with BDD framework like behatWorking 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.
<?php
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);
$this->webDriver->manage()->window()->maximize();
}
public function testFrames()
{
$this->webDriver->get(“https://www.softpost.org/selenium-test-page”);
//Switch to frame with name “g”
$this->webDriver->switchTo()->frame(“g”);
echo (“
Portion of HTML Source of Frame -> ” . substr($this->webDriver->getPageSource(), 0, 300));
echo (“
********************************************************************
”);
$this->webDriver->switchTo()->defaultContent();
echo (“
Portion of HTML Source of Main window -> ” . substr($this->webDriver->getPageSource(), 0, 300));
}
public function tearDown()
{
//Quit the driver
$this->webDriver->quit();
}
}
?>
Web development and Automation testing
solutions delivered!!