1

I am trying to drag an element and drop to another element on the page. My code runs without any errors. But the drag actually doesn't happen. It's able to find both the elements. I tried all the options listed below:

driver.browser.action.drag_and_drop(fromobject.native, 
toobject.native).perform

fromobject.drag_to toobject

driver.browser.action.move_to(toobject.native).release.perform

fromobject.drag_and_drop_on toobject
orde
  • 5,233
  • 6
  • 31
  • 33
aruna
  • 13
  • 3
  • Did you read [this](http://stackoverflow.com/questions/14210051/how-to-automate-drag-drop-functionality-using-selenium-webdriver-java) SO question? – Jeroen Heier May 16 '17 at 04:00

1 Answers1

1

If from_element.drag_to to_element doesn't work for you, then it's probably not going to be possible to do it directly with capybara/selenium. The reason for this is that drag and drop support in drivers is highly dependent on what events your code is looking for. Current versions of selenium implement it as the events mouse down, mouse move, mouse up whereas your code may be looking for drag start, drag, drag end events, etc. Because of this, to make it work you'll need to create synthetic events using execute_script to trigger the behavior you want. If you are using specific libraries someone may have already implemented this nicely for you - for instance, if you're using JQuery UI Sortable elements there is https://github.com/mattheworiordan/jquery.simulate.drag-sortable.js

Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78
  • Thank You , will be trying this, I am guessing this should help, will post the output. – aruna May 17 '17 at 23:05
  • Tried with an execute_script, still same issue, test runs without any error but the drag and drop actually does not happen. Any other solution would be really helpful – aruna May 26 '17 at 17:26
  • @aruna You tried what with `execute_script` ? - Any solution for this going to be completely dependent on exactly how your app implements detection of drag and drop so there really are no other solutions to propose without you figuring out exactly what your app is looking for. – Thomas Walpole May 26 '17 at 17:29