Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 22 additions & 31 deletions src/Selenium2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1025,44 +1025,35 @@ public function keyUp(string $xpath, $char, ?string $modifier = null)

public function dragTo(string $sourceXpath, string $destinationXpath)
{
$source = $this->findElement($sourceXpath);
$destination = $this->findElement($destinationXpath);
$source = $this->findElement($sourceXpath);
$target = $this->findElement($destinationXpath);

$this->getWebDriverSession()->moveto(array(
'element' => $source->getID()
));

$script = <<<JS
(function (element) {
var event = document.createEvent("HTMLEvents");
$this->getWebDriverSession()->moveto(array('element' => $source->getID()));
$this->getWebDriverSession()->buttondown();

event.initEvent("dragstart", true, true);
event.dataTransfer = {};
$this->executeJsOnElement($source, <<<'JS'
(function (sourceElement) {
window['__minkDragAndDropSourceElement'] = sourceElement;

element.dispatchEvent(event);
}({{ELEMENT}}));
JS;
$this->executeJsOnElement($source, $script);
sourceElement.dispatchEvent(new DragEvent('dragstart', {bubbles: true, cancelable: true}));
}({{ELEMENT}}));
JS
);

$this->getWebDriverSession()->buttondown();
if ($destination->getID() !== $source->getID()) {
$this->getWebDriverSession()->moveto(array(
'element' => $destination->getID()
));
}
$this->getWebDriverSession()->moveto(array('element' => $target->getID()));
$this->getWebDriverSession()->buttonup();

$script = <<<JS
(function (element) {
var event = document.createEvent("HTMLEvents");
$this->executeJsOnElement($target, <<<'JS'
(function (targetElement) {
var sourceElement = window['__minkDragAndDropSourceElement'];

event.initEvent("drop", true, true);
event.dataTransfer = {};

element.dispatchEvent(event);
}({{ELEMENT}}));
JS;
$this->executeJsOnElement($destination, $script);
sourceElement.dispatchEvent(new DragEvent('drag', {bubbles: true, cancelable: true}));
targetElement.dispatchEvent(new DragEvent('dragover', {bubbles: true, cancelable: true}));
targetElement.dispatchEvent(new DragEvent('drop', {bubbles: true, cancelable: true}));
sourceElement.dispatchEvent(new DragEvent('dragend', {bubbles: true, cancelable: true}));
}({{ELEMENT}}));
JS
);
}

public function executeScript(string $script)
Expand Down