Drag and drop functionality not working properly in selenium webdriver for chrome browser
NickName:Shivani Thaman Ask DateTime:2016-08-30T15:55:16

Drag and drop functionality not working properly in selenium webdriver for chrome browser

I have written below code to drag an element and add it in workspace. There is no error in console window however drap drop is not performed on chrome browser.

WebElement dragElement = driver.findElement(By.xpath("//*[@id='sidebar-wrapper']/div/div/nginclude/div[2]/accordion/div/div[1]/div[2]/div/div/div[1]/div[2]"));
Thread.sleep(4000);
System.out.println("Element Selected to Drag");
WebElement dropElement = driver.findElement(By.xpath("//*[@id='workspace']/div/div/div/div[2]/div/div/div/div[2]/span"));
Thread.sleep(4000);

act.clickAndHold(dragElement).moveToElement(dropElement).release().build().perform();

I have tried multiple times but not able to succeed. Please provide your inputs

Copyright Notice:Content Author:「Shivani Thaman」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/39221848/drag-and-drop-functionality-not-working-properly-in-selenium-webdriver-for-chrom

Answers
Guy 2016-08-30T08:14:42

You can try give the location of the element\n\nact.clickAndHold(dragElement).perform();\nact.moveToElement(dropElement, dropElement.getLocation().getX(), dropElement.getLocation().getY()).perform();\nact.release(dropElement).perform();\n",


Chaitali 2016-08-30T09:57:19

This is another method provided in the Selenium documentation here: http://www.seleniumhq.org/docs/03_webdriver.jsp#drag-and-drop. \n\nWebElement dragElement = driver.findElement(By.xpath(\"//*[@id='sidebar-wrapper']/div/div/nginclude/div[2]/accordion/div/div[1]/div[2]/div/div/div[1]/div[2]\"));\n\nWebElement dropElement = driver.findElement(By.xpath(\"//*[@id='workspace']/div/div/div/div[2]/div/div/div/div[2]/span\"));\n\n(new Actions(driver)).dragAndDrop(dragElement, dropElement).perform();\n",


Vikas Rathore 2016-08-30T11:53:34

You can use below code for drag and drop but I suggest you to optimize your xpath. It might be the real problem for you.\n\nWebElement source = driver.findElement(By.xpath(\"//*[@id='sidebar-wrapper']/div/div/nginclude/div[2]/accordion/div/div[1]/div[2]/div/div/div[1]/div[2]\"));\nThread.sleep(4000);\nSystem.out.println(\"Element Selected to Drag\");\nWebElement target = driver.findElement(By.xpath(\"//*[@id='workspace']/div/div/div/div[2]/div/div/div/div[2]/span\"));\nThread.sleep(4000);\nActions builder = new Actions(driver);\nAction mouseOverHome = builder.dragAndDrop(source, target).build();\nmouseOverHome.perform(); \n",


More about “Drag and drop functionality not working properly in selenium webdriver for chrome browser” related questions

How to get drag and drop working with Selenium WebDriver

I am having persistent problem on getting the drag and drop functionality working with Selenium WebDriver. According the WebDriver documentation the drag/drop should work out of the box with comma...

Show Detail

Python Selenium WebDriver drag-and-drop

I cannot get drag-and drop working with the Python WebDriver bindings. I am working with Google Chrome and Firefox on Mac OS X. There is a thread here where someone had a similar problem. I have t...

Show Detail

Am not able to handle the drag and drop functionality using selenium webdriver in chrome browser

I'm not able to handle the drag and drop functionality using selenium webdriver in chrome browser. This is my piece of code: WebDriver driver=new ChromeDriver(); String URL = "http://www.dhtmlx.com/

Show Detail

Drag and drop functionality not working properly in selenium webdriver for chrome browser

I have written below code to drag an element and add it in workspace. There is no error in console window however drap drop is not performed on chrome browser. WebElement dragElement = driver.

Show Detail

Drag and Drop functionality is not working in selenium Webdriver

I am trying to learn selenium. I have the following site where the drag and drop functionality is available http://html5demos.com/drag#. I am trying to do the drag and drop using the below codes. B...

Show Detail

selenium drag and drop method not working on chrome browser

fully functional drag and drop method exported from selenium IDE fails to work on webDriver. the test on webDriver passes with out any action performed. the version of chrome is 75.0.3770.100. the

Show Detail

Ruby selenium webdriver drag and drop

I am trying to perform drag and drop operation using selenium webdriver and ruby, and I tried the following options: Option 1: based on http://rubydoc.info/gems/selenium-webdriver/0.0.28/Selenium/

Show Detail

How to automate drag & drop functionality using Selenium WebDriver Java

How to automate drag & drop functionality using Selenium WebDriver in java?

Show Detail

drag and drop not working using selenium python headless mode

Recently, I created python script to test web application using Selenium Chrome Webdriver. Most of the action is done by Selenium Chrome webdriver. However, Drag_and_drop Actionchain is not working...

Show Detail

Drag & Drop not working with Selenium Python

I want to implement a simple drag and drop with selenium python. I am using Chrome WebDriver and below is my code. Nothing happens. Any help is highly apprecited. from selenium.webdriver.common.by

Show Detail