Is drag-and-drop possible in watir-webdriver?

戏子无情 提交于 2019-11-30 17:29:10

I don't know if you found the answer for this by now, but this is how I do it for Firefox:

my_element.fire_event("onmousedown")
driver=browser.driver
driver.action.click_and_hold(my_element.wd).perform

sleep 2
driver.action.move_to(target.wd).perform

sleep 2
my_element.fire_event("onmouseup")

It fails without the delays, but it works fine with them on FF5.

require 'rubygems'
require 'watir-webdriver'

module Watir
  class Element
    def drag_and_drop_on(other)
      assert_exists
      driver.action.drag_and_drop(@element, other.wd).perform
    end
  end
end

profile = Selenium::WebDriver::Firefox::Profile.new
profile.native_events = true

b = Watir::Browser.new :firefox, :profile => profile
b.goto "http://jqueryui.com/demos/droppable/default.html"

b.element(:id => "draggable").drag_and_drop_on(b.element(:id => "droppable"))

h3manth.com

Did not use it myself, but there is some documentation about using Using drag and drop here: https://github.com/SeleniumHQ/selenium/wiki/Tips-And-Tricks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!