aruna
aruna

Reputation: 13

drag and drop using selenium ruby capybara

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

Upvotes: 1

Views: 1713

Answers (1)

Thomas Walpole
Thomas Walpole

Reputation: 49890

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

Upvotes: 1

Related Questions