Search code examples
javaseleniumdrag-and-drop

Unable to drag Element/Item into the Drop Area/Container


Unable to drag Element/Item into the Drop Area/Container

Tech/Softwares used:

  • IDE: Eclipse
  • Framework for testing: Selenium
  • Language: Java
  • Browser: Microsoft Edge - Version 85.0.564.51

Issue:

  • I'm unable to drag the given Element/Item into the Drop Area/Container (See Images)
  • I've also used different Xpaths/Selectors i.e. By-CSS,By-Xpath or By-Class
  • It seems that the Element/Item is selected and moved a pixel or two after which the Element/Item freezes and is not dragged to the Drop Area/Container below

My Attempt:

  • So i've tried different drag and drop functions such as the ones below:-

      Actions action = new Actions(drv);
      //Source 
      WebElement sourceLocator = drv.findElement(By.className(Item));
     //Destination
      WebElement targetLocator = drv.findElement(By.cssSelector(DropArea));
     //Click -> Hold -> Drag -> Drop
      action.clickAndHold(sourceLocator).moveToElement(targetLocator)
      .release()
      .build()
      .perform();
    
  • I've also tried using 'dragAndDrop instead of clickAndHold'

       `action.dragAndDrop(sourceLocator, targetLocator).build().perform();`
    

Like I said earlier, The item/element is selected -> Moves a pixel or two then it freezes just above the container (The container pops-up from below as per functionality)

Green box is the item/element to be dragged and droped - Red box is the area where the item/element should be droped

As you can see, the item/element is stuck/frozen right above the drop area

Outcome that is expected - Element has been dragged and dropped (Done manually) in the picture


Solution

  • You should try to do it by JavaScript, use the JavaExecutor class from selenium execute the scripts that are in this post, it could work for you

    Why drag and drop is not working in Selenium Webdriver?