How do I drag and drop using poltergeist?
Asked Answered
H

1

8

Right now I'm using the selenium driver with Capybara, but I'd like to switch to using Poltergeist. A lot of the interface I'm testing, though, involves dragging and dropping elements in particular locations on the page. I've written the following method for dragging and dropping, which works in selenium:

def drag_drop(page, draggable, droppable, xoffset, yoffset)
  driver = page.driver.browser
  driver.mouse.move_to(draggable.native, draggable.native.size.height / 2, draggable.native.size.width / 2)
  driver.mouse.down
  driver.mouse.move_to(droppable.native, droppable.native.size.height / 2 + yoffset, droppable.native.size.width / 2 + xoffset)
  driver.mouse.up
end

How would I go about writing something like this in poltergeist?

Humanitarianism answered 1/5, 2013 at 5:22 Comment(0)
D
3

I don't know if it's exactly what you're looking for, but Capybara has an API for dragging which Poltergeist supports.

Dacy answered 2/5, 2013 at 21:13 Comment(1)
Yeah, I've tried that, but it's not precise enough. I need to be able to drag and drop to coordinates, not just one element on top of another. If I just use drag_to it doesn't register as having landed in the appropriate area.Humanitarianism

© 2022 - 2024 — McMap. All rights reserved.