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 28, 2018 in Selenium by code_ninja
• 6,300 points
5,152 views

1 answer to this question.

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();

For more don't forget to check out this blog on how to drag and drop in Selenium?

answered Mar 28, 2018 by nsv999
• 5,500 points

Related Questions In Selenium

0 votes
0 answers

how to do search name and drag and drop in hybrid frame work java selenium?

i have to do following things first i ...READ MORE

Sep 10, 2020 in Selenium by anonymous
• 120 points
530 views
+1 vote
2 answers

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

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

answered Nov 28, 2018 in Selenium by Rijhu mal
15,192 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,460 points
4,243 views
0 votes
2 answers

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,500 points
13,687 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,149 views
0 votes
2 answers

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

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

answered Sep 4, 2020 in Selenium by Sri
• 3,190 points
2,897 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,910 points
7,229 views
0 votes
2 answers

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

Hello Nitin, as the Like button on ...READ MORE

answered Aug 23, 2019 in Selenium by Abha
• 28,140 points
5,452 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP