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 behatExecuting JS in Selenium in php
Below example shows how to execute the JavaScript in Selenium in PHP.
<?php
class MyTest extends PHPUnit_Framework_TestCase {
protected $driver;
public function setUp()
{
$capabilities = array(WebDriverCapabilityType::BROWSER_NAME => ‘chrome’);
$this->driver = RemoteWebDriver::create(‘https://localhost:4444/wd/hub’, $capabilities);
$this->driver->manage()->window()->maximize();
}
public function testJS()
{
$this->driver->get(“https://www.softpost.org/selenium-test-page”);
$src = $this->driver->executeScript(‘return document.body.innerHTML;’);
echo (“Source of page -> ” . $src);
//click on the radio button using java script
//Notice how we have passed the argument to the java script code.
$elements = $this->driver->findElements(WebDriverBy::xpath(“//input[@value=’female’]”));
$this->driver->executeScript(‘arguments[0].click();’,$elements);
sleep(2);
}
public function tearDown()
{
//Quit the driver
$this->driver->quit();
}
}
?>
Web development and Automation testing
solutions delivered!!