Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Watir - drag and drop not working

I need to test some functionality where I need to drag and drop some UI elements.

I tried to do this on this page http://www.html5rocks.com/en/tutorials/dnd/basics/ :

browser.divs(:class => "column")[-2].drag_and_drop_on browser.divs(:class => "column")[-3]

In chrome, I don’t see anything happening. In firefox, I see the that the mouse button is down, but nothing else happens – the element didn't move. I tried in other pages as well and this never seemed to work.

I also tried this workaround (which is recommended in multiple threads) and it doesn’t work either:

my_element = browser.divs(:class => "column")[-4]
target = browser.divs(:class => "column")[-3]
my_element.fire_event("onmousedown")
driver = browser.driver
driver.action.click_and_hold(my_element.wd).perform
driver.action.move_to(target.wd).perform
target.fire_event("onmouseup”)

I'm using ruby 1.9.3 on mac. I also tried ruby 2.1.5 on windows and the result was the same.

Is there a way to drag and drop with watir?

like image 926
npassosg Avatar asked Nov 09 '22 12:11

npassosg


1 Answers

This is what eventually got it to work (not fancy at all, but it did it for me):

# monkey patch for webdriver: copy and paste in IRB
module Selenium
  module WebDriver
    class ActionBuilder
      def drag_and_drop(source, target)
        click_and_hold source
        move_to        target, 0, 0
        release        target

        self
      end
    end # ActionBuilder
  end # WebDriver
end # Selenium
like image 159
npassosg Avatar answered Jan 04 '23 02:01

npassosg