protractor icon indicating copy to clipboard operation
protractor copied to clipboard

Protractor failed to drag and drop elements

Open wangfeiv opened this issue 11 years ago • 7 comments

I tried to use protractor to simulate dragAndDrop, but it did not work, and there was no any error about it, below is my test code:

this.dragAndDropDashboardTab = function(source, target) { // Way-1: it did not work // browser.actions().dragAndDrop(source, target).perform(); // browser.actions() // .mouseDown(source) // .mouseMove(target) // .mouseUp() // .perform(); // Way-2: it did not work // browser.actions().dragAndDrop(source, target).perform(); };

Who will tell me the work around? And would you like to help me fix this issue?

wangfeiv avatar Jul 01 '15 07:07 wangfeiv

Duplicate of https://github.com/angular/protractor/issues/1205 or maybe https://github.com/angular/protractor/issues/583 if you are using Chrome.

juliemr avatar Jul 01 '15 17:07 juliemr

@juliemr just like @wangfeiv I tried both:

browser.actions().dragAndDrop(draggable_element, target_element).perform();

and:

browser.actions().
   mouseDown(draggable_element).
   mouseMove(target_element).
   mouseUp().
perform();

where draggable_element and target_element are properly retrieved, i.e. this expectations are satisfied:

expect(draggable_element.isPresent()).toEqual(true);
expect(target_element.isPresent()).toEqual(true);

draggable_element is a div with an AngularJS directive that adds draggable=true, while draggable_element is a div with an AngularJS directive that handles the drop event by adding a row with some text inside a table within the same div. Here is a screenshot:

schermata da 2015-08-11 14 17 51

The full code of my spec looks like this:

var draggable_element = element(...);
var target_element = element(...);
expect(draggable_element.isPresent()).toEqual(true);
expect(target_element.isPresent()).toEqual(true);
browser.actions().dragAndDrop(draggable_element, target_element).perform();
expect(element.all(by.css('tr')).count()).toEqual(1);

The last expectation fails: Expected 0 to equal 1.

I've read #1205, but it seems to me only a discussion about how to improve the syntax. Instead, I would like to know if and how I can test drag and drop.

Also, where should I search actions documentation? The Official API is really too short.

About #583, my test is failing both in Chrome and in Firefox. My OS is Ubuntu Gnome 14.04.

Note that I'm 100% sure that my directives work fine. I checked with a couple of demo apps and with several unit-tests.

marcoliceti avatar Aug 11 '15 12:08 marcoliceti

@marcoliceti did you ever figure this out currently reading through trying to figure out how to drag and drop an element and cannot get it to work for me! My code is pretty much the same but cannot find a way to get it working.

thewebuiguy avatar Jan 21 '16 09:01 thewebuiguy

@EvanBurbidge: nope :-/

In the end I removed Protractor tests from my project, since it's very hard to test non-trivial stuff like drag & drop and it's also hard to get help, since it's usually not clear if issues are related to Protractor itself or to Selenium.

marcoliceti avatar Jan 21 '16 14:01 marcoliceti

That's a shame, this is an important feature...

pidupuis avatar Feb 29 '16 16:02 pidupuis

I have the same problem(

krasevych avatar Jul 15 '16 16:07 krasevych

I got the same issue. I saw the content of the page has been "selected when clicking the mouse down, hold and move". Is there any solution for this case.

binhvtle avatar Aug 01 '18 02:08 binhvtle