Selenium advanced operations in php

Below example shows how to perform complex actions using Selenium in PHP like drag and drop, moving to element, double clicking on an element, right clicking on an element etc.
 
<?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 testActions()
{
$this->webDriver->get(“https://www.softpost.org/selenium-test-page”);

$e1 = $this->webDriver->findElement(WebDriverBy::id(‘fn’));
$e2 = $this->webDriver->findElement(WebDriverBy::linkText(‘Selenium in Java’));

$action = new WebDriverActions($this->webDriver);
$action->moveToElement($e1)->click($e2)->perform();
sleep(3);
//Similarly you can perform below actions.
//clickAndHold(), contextClick(), doubleClick()
//dragAndDrop(), dragAndDropBy(), moveByOffset(), moveToElement()
//keyDown(), keyUp(), release(), sendKeys()

}

public function tearDown()
{
//Quit the driver
$this->webDriver->quit();
}
}
?>
                    

Web development and Automation testing

solutions delivered!!