dragAndDrop not working

306 views
Skip to first unread message

Viktor Amkhinich

unread,
Apr 20, 2016, 11:10:26 AM4/20/16
to Serenity BDD Users Group
Hi All,

In my Selenium 2.48.2/Java8 project, drag and drop behave very strangely. When I execute the following code (drag the from element to the destination one):

Actions builder = new Actions(driver);
Point p = destination.getLocation();
builder.dragAndDropBy(from, p.x, p.y).perform();

it gets stuck in the last statement, until I move the mouse in the browser window; after that, code resumes running, but drag/drop do not happen. I tried other code samples found on the net, like this one:

Actions builder = new Actions(driver);

builder.clickAndHold(from).perform();

try {Thread.sleep(3000);} catch (InterruptedException e) {e.printStackTrace();}

builder.moveToElement(destination).perform();

builder.release().perform();


with the same result.


Thanks


Viktor

Selenium Vietnam

unread,
Apr 26, 2016, 12:28:36 AM4/26/16
to Serenity BDD Users Group
In Serenity BDD you should try with.

withAction().dragAndDrop(source, target);

source and targe is WebElement object.

Sampathkumar S

unread,
Apr 26, 2016, 1:39:24 AM4/26/16
to Serenity BDD Users Group
There are two ways you can perform drag and drop..

Actions newAction = new Actions(getDriver());

final WebElement sourceLocation=getDriver().findElement(By.xpath("//SourceElement"));
final WebElement targetLocation = getDriver().findElement(By.xpath("//Targetelement"));

newAction
.dragAndDrop(sourceLocation,targetLocation ).build().perform();
/***or***/
newAction
.dragAndDropBy(source, xOffset, yOffset);

Viktor Amkhinich

unread,
Apr 26, 2016, 1:15:43 PM4/26/16
to Serenity BDD Users Group
Thanks, I tried those suggested by Selenium Vietnam and Sampathkumar S, plus many others. In fact, there's no "stuck" effect when Chrome is used, but drag/drop is not working all the same. I recently found out that the page is generated by Angular. So far, I did not have any drag/drop problems with non-Angular pages. Is there something specific with Angular ?

Sampathkumar S

unread,
Apr 27, 2016, 8:41:07 AM4/27/16
to Serenity BDD Users Group
Its challenge of determining when the page is ready to locate elements in AngulaJS web application. As per my knowledge unless and until if you are able to locate element for AngularJS page, drag&drop should work.

We should be able to understand your problem if you can provide more details. (what error you are getting, html source code and screenshots etc.)

Thanks,
Sampath
Reply all
Reply to author
Forward
0 new messages