Selenium + Java - drag and drop not working on selenium 3.8

0 votes

I have tried the below code for drag and droppping an element. But it is only selecting the element. Hold and drop is not happening.

WebElement source = driver.findElement(By.xpath("//tbody[@class ='lt-body']//tr[@data-test-id='table-row-id-20']//td[contains(@id,'ember')]//div[contains(@id,'ember')]//*[name()='svg']//*[name()='ellipse']"));
WebElement destination = driver.findElement(By.xpath("//tbody[@class ='lt-body']//tr[@data-test-id='table-row-id-3']//td[contains(@id,'ember')]//div[contains(@id,'ember')]//*[name()='svg']//*[name()='ellipse']"));

Actions builder = new Actions(driver);
int x2 =destination.getLocation().getX();
int y2 = destination.getLocation().getY();
builder.clickAndHold(source);
builder.moveByOffset(x2,y2);
builder.moveToElement(destination);
builder.release();
builder.perform();

And, I tried this one as well.

builder.clickAndHold(source).moveByOffset(x2,y2).moveToElement(destination).release().build().perform();

Tried with Robot as well. Everytime I can only see both source and destination element getting selected. But not dragged and dropped.

Also tried dragAndDrop of ActionsChain. That too didn't work.

Mar 27, 2018 in Selenium by code_ninja
• 5,710 points
1,012 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

How about you try adding the below function calls:

new Actions(driver)
                .moveToElement(source)
                .pause(Duration.ofSeconds(1))
                .clickAndHold(source)
                .pause(Duration.ofSeconds(1))
                .moveByOffset(1, 0)
                .moveToElement(destination)
                .moveByOffset(1, 0)
                .pause(Duration.ofSeconds(1))
                .release().perform();
answered Mar 27, 2018 by nsv999
• 5,030 points

Related Questions In Selenium

+1 vote
2 answers

Drop-down menu option value not working using Selenium (Python)

from selenium.webdriver.support.select import Select inputElementGa ...READ MORE

answered Nov 28, 2018 in Selenium by Rijhu mal
2,692 views
0 votes
1 answer

Python Selenium WebDriver drag-and-drop

I have verified that this does in ...READ MORE

answered Aug 23, 2018 in Selenium by Meci Matt
• 9,400 points
278 views
0 votes
1 answer

Firefox Error: “Your connection is not secure” while launching driver with Selenium 3.0.1 using Java

Download Firefox 55 beta and set capabilities.setCapability("acceptInsecureCerts", true); Here ...READ MORE

answered Sep 17, 2018 in Selenium by Meci Matt
• 9,400 points
149 views
0 votes
1 answer

Drag and drop in selenium

Here is what I did, you can ...READ MORE

answered Jan 7 in Selenium by Dish
61 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,030 points
65 views
0 votes
1 answer
0 votes
1 answer

What is the role of TestNG & JUnit frameworks in Selenium?

Well TestNG and JUnit are test frameworks ...READ MORE

answered Apr 18, 2018 in Selenium by king_kenny
• 3,590 points
128 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
438 views
0 votes
1 answer
0 votes
1 answer

Python & Selenium: How to find and click on YouTube's Like button

Use the CSS Selector button to like: #watch8-sentiment-actions ...READ MORE

answered Mar 26, 2018 in Selenium by nsv999
• 5,030 points
431 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.