Skip to content

Commit

Permalink
Fix D&D on Selenium 3
Browse files Browse the repository at this point in the history
  • Loading branch information
uuf6429 committed Jan 11, 2025
1 parent bedccba commit da03000
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/Selenium2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1008,33 +1008,31 @@ public function dragTo(string $sourceXpath, string $destinationXpath)
));

$script = <<<JS
(function (element) {
var event = document.createEvent("HTMLEvents");
(function (sourceElement) {
window['__minkDragAndDropSourceElement'] = sourceElement;
event.initEvent("dragstart", true, true);
event.dataTransfer = {};
element.dispatchEvent(event);
sourceElement.dispatchEvent(new DragEvent('dragstart', {bubbles: true, cancelable: true}));
}({{ELEMENT}}));
JS;
$this->executeJsOnElement($source, $script);

$this->getWebDriverSession()->buttondown();
if ($destination->getID() !== $source->getID()) {
if ($destination->getID() === $source->getID()) {
$this->getWebDriverSession()->click(0);

Check warning on line 1020 in src/Selenium2Driver.php

View check run for this annotation

Codecov / codecov/patch

src/Selenium2Driver.php#L1020

Added line #L1020 was not covered by tests
} else {
$this->getWebDriverSession()->buttondown();
$this->getWebDriverSession()->moveto(array(
'element' => $destination->getID()
));
$this->getWebDriverSession()->buttonup();
}
$this->getWebDriverSession()->buttonup();

$script = <<<JS
(function (element) {
var event = document.createEvent("HTMLEvents");
(function (targetElement) {
targetElement.dispatchEvent(new DragEvent('dragover', {bubbles: true, cancelable: true}));
event.initEvent("drop", true, true);
event.dataTransfer = {};
targetElement.dispatchEvent(new DragEvent('drop', {bubbles: true, cancelable: true}));
element.dispatchEvent(event);
window['__minkDragAndDropSourceElement'].dispatchEvent(new DragEvent('dragend', {bubbles: true, cancelable: true}));
}({{ELEMENT}}));
JS;
$this->executeJsOnElement($destination, $script);
Expand Down

0 comments on commit da03000

Please sign in to comment.