1

I am working with selenium drag and drop function. It drags the element but can not drop the element. Both the source and destination element are in the same frame and there doesn't seem to be any issues at all.

Below are the code clocks I have used.

Actions act=new Actions(Driver);
WebElement Destination=Driver.findElement(By.xpath("//*@id='dvdoccategories']/ul[1]/li/ul[1]/li/span"));
WebElement source=Driver.findElement(By.xpath("//*@id='dvuntaggedcntr']/div/a/img[1]"));
Boolean js= false;
js=Destination.isDisplayed();
System.out.println("destination displayed " + js);  // This return true ,proves there is no frame issue
act.dragAndDrop(source, Destination).build().perform();

Actions act=new Actions(Driver);
act.clickAndHold(source);
act.moveToElement(Destination);
act.release(source);
act.build().perform();

Point coordinates1 = source.getLocation();
Point coordinates2 = Destination.getLocation(); 
Robot rb=new Robot();
rb.setAutoDelay(15);
rb.keyPress(KeyEvent.VK_F11);
act.dragAndDropBy(source, coordinates2.getX(),coordinates2.getY());

    Point coordinates1 = source.getLocation();
    Point coordinates2 = Destination.getLocation(); 
    Robot rb=new Robot();
    rb.mouseMove(coordinates1.getX(), coordinates1.getY());
    rb.mousePress(InputEvent.BUTTON1_MASK);
    rb.mouseMove(coordinates2.getX(), coordinates2.getY());
    rb.mouseRelease(InputEvent.BUTTON1_MASK);

****** There is no error shown during the execution. Source element can be seen as being dragged but is not dropped at destination. Please help

  • Please refer seleniumeasy.com/selenium-tutorials/… [dragAndDropUsingSelenium]. – srshma Jun 12 '18 at 12:25
  • 1
    Add your code what have you tried and the error message. – Bharat Mane Jun 12 '18 at 12:33
  • Hi Bharat, Please check the code block above. Thanks – Isha Jun 13 '18 at 13:11
  • How to drag a image if draggable is set to false in selenium? – Akash Khair Aug 26 '19 at 18:06
2

With the use of "Action" class, we can perform "drag and drop" function in selenium. First, locate the draggable element then use the following code for "drag and drop".

Actions builder = new Actions(driver);
builder.dragAndDropBy(draggable, 100, 100).build().perform();

The above code will drag the located element and drop at the position 100,100. So you can specify the position where you want to drop.

  • Hi shanila, Thanks, I have already tried this option, Please check my code blocks and let me know if there is any other option left which I can try – Isha Jun 13 '18 at 13:10
  • @Isha why you have declared the code "Actions act=new Actions(Driver);" twice.can you please recheck your code. – shanila Jun 13 '18 at 15:35
  • @Isha why you have declared the code "Actions act=new Actions(Driver);" twice which is not correct.And too instantiate a new action object you have to use the syntax "Actions builder = new Actions(driver);"can you please recheck your code. – shanila Jun 13 '18 at 15:44
  • this has been declared only once. These code blocks have been executed seperately.not altogether – Isha Jun 14 '18 at 14:31
0

The code is works fine if you scroll your mouse over the destination element and keep scrolling it right there just like mouse hover.

  • Could you share the code you used? – corsiKa Jul 2 '18 at 16:01
  • I did it manually and drag and drop code (already mentioned above) worked. – Isha Jul 4 '18 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.