diff --git a/src/Selenium2Driver.php b/src/Selenium2Driver.php index 01e86c27..543ff273 100755 --- a/src/Selenium2Driver.php +++ b/src/Selenium2Driver.php @@ -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 = <<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 = <<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)