title: Why drag and drop is not working in Selenium Webdriver?
body: <p>I am trying to drag an element into another element using Selenium WebDriver but it's not working. I tried all the solutions which I can find on internet but none of the solutions seems to be working for me. </p>
  
  <pre><code>WebElement sourceelement = driver.findElement(By.cssSelector("XXX"));
  WebElement destelement = driver.findElement(By.cssSelector("YYY"));
  </code></pre>
  
  <p>Code1:-</p>
  
  <pre><code>Actions builder = new Actions( _controls.getDriver());
  builder.dragAndDrop(sourceelement, destelement);
  </code></pre>
  
  <p>Code2:- </p>
  
  <pre><code>Actions builder = new Actions(_controls.getDriver());
  Action dragAndDrop =
  builder.clickAndHold(sourceelement).moveToElement(destelement).release(destelement).build();
  Thread.sleep(2000);
  dragAndDrop.perform()
  </code></pre>
  
  <p>Code3:-</p>
  
  <pre><code>Point coordinates1 = sourceelement.getLocation();
  Point coordinates2 = destelement.getLocation();  
  Robot robot = new Robot();           
  robot.mouseMove(coordinates1.getX(), coordinates1.getY());
  robot.mousePress(InputEvent.BUTTON1_MASK);
  robot.mouseMove(coordinates2.getX(), coordinates2.getY());
  robot.mouseRelease(InputEvent.BUTTON1_MASK);
  Thread.sleep(2000);
  </code></pre>
  
  <p>Code4:-</p>
  
  <pre><code>final String java_script =
  "var src=arguments[0],tgt=arguments[1];var dataTransfer={dropEffe" +
                  "ct:'',effectAllowed:'all',files:[],items:{},types:[],setData:fun" +
                  "ction(format,data){this.items[format]=data;this.types.append(for" +
                  "mat);},getData:function(format){return this.items[format];},clea" +
                  "rData:function(format){}};var emit=function(event,target){var ev" +
                  "t=document.createEvent('Event');evt.initEvent(event,true,false);" +
                  "evt.dataTransfer=dataTransfer;target.dispatchEvent(evt);};emit('" +
                  "dragstart',src);emit('dragenter',tgt);emit('dragover',tgt);emit(" +
                  "'drop',tgt);emit('dragend',src);";
  
          ((JavascriptExecutor)_controls.getDriver()).executeScript(java_script, sourceelement, destelement);
          Thread.sleep(2000);
  </code></pre>
  
  <p>None of the above code is working for me. All the above runs without any error but drag and drop is not happening in the application. Anyone having any other solution ? Thanks.</p>