function Selenium2Driver::dragTo
Overrides CoreDriver::dragTo
File
-
vendor/
lullabot/ mink-selenium2-driver/ src/ Selenium2Driver.php, line 1020
Class
- Selenium2Driver
- Selenium2 driver.
Namespace
Behat\Mink\DriverCode
public function dragTo(string $sourceXpath, string $destinationXpath) {
$source = $this->findElement($sourceXpath);
$destination = $this->findElement($destinationXpath);
if ($this->isW3C()) {
$this->scrollElementIntoView($source);
$actions = array(
'actions' => [
[
'type' => 'pointer',
'id' => 'mouse1',
'parameters' => [
'pointerType' => 'mouse',
],
'actions' => [
[
'type' => 'pointerMove',
'duration' => 0,
'origin' => [
Element::WEB_ELEMENT_ID => $source->getID(),
],
'x' => 0,
'y' => 0,
],
[
'type' => 'pointerDown',
"button" => 0,
],
[
'type' => 'pointerMove',
'duration' => 0,
'origin' => [
Element::WEB_ELEMENT_ID => $destination->getID(),
],
'x' => 0,
'y' => 0,
],
[
'type' => 'pointerUp',
"button" => 0,
],
],
],
],
);
$this->getWebDriverSession()
->postActions($actions);
$this->getWebDriverSession()
->deleteActions();
}
else {
$this->getWebDriverSession()
->moveto(array(
'element' => $source->getID(),
));
$script = <<<JS
(function (element) {
var event = document.createEvent("HTMLEvents");
event.initEvent("dragstart", true, true);
event.dataTransfer = {};
element.dispatchEvent(event);
}({{ELEMENT}}));
JS;
$this->withSyn()
->executeJsOnElement($source, $script);
$this->getWebDriverSession()
->buttondown();
$this->getWebDriverSession()
->moveto(array(
'element' => $destination->getID(),
));
$this->getWebDriverSession()
->buttonup();
$script = <<<JS
(function (element) {
var event = document.createEvent("HTMLEvents");
event.initEvent("drop", true, true);
event.dataTransfer = {};
element.dispatchEvent(event);
}({{ELEMENT}}));
JS;
$this->withSyn()
->executeJsOnElement($destination, $script);
}
}