在 watir-webdriver 中可以拖放吗? [英] Is drag-and-drop possible in watir-webdriver?
问题描述
我想将一个元素拖放到另一个元素的位置,从 watir-webdriver 脚本中触发.
I would like to drag-and-drop one element to the position of another, triggered from within a watir-webdriver script.
拖放"是指拾取一个可拖动元素并将其释放到另一个元素上.可能"是指可以从 watir-webdriver 脚本执行的任何拖放方法.这包括代码片段、第三方 gem 等.
By "drag-and-drop" I mean picking up a draggable element and releasing it on another. By "possible" I mean any method for drag/drop that can be executed from a watir-webdriver script. This includes code snippets, third party gems, etc.
据我了解,拖放是对核心 watir-webdriver 的功能请求(在询问时),因此我(原则上)正在寻找替代方案.
As I understand it drag-and-drop is a feature request for core watir-webdriver (at time of asking), so I'm looking (in principle) for an alternative.
更新拖放现在是核心 watir-webdriver 的一部分(我相信从 0.5.0 开始)
UPDATE drag-and-drop is now part of core watir-webdriver (as of 0.5.0, I believe)
更新 2 对于那些寻求启迪的人来说,这现在是可能的(从 0.5.0 版开始):
UPDATE 2 For those seeking enlightenment, this is now possible (as of version 0.5.0):
a = browser.div(:id => "draggable")
b = browser.div(:id => "droppable")
a.drag_and_drop_on b
和
a = browser.div(:id => "draggable")
a.drag_and_drop_by 100, -200
推荐答案
我不知道你现在是否找到了答案,但这就是我在 Firefox 上的做法:
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")
它没有延迟就失败了,但在 FF5 上它可以正常工作.
It fails without the delays, but it works fine with them on FF5.
这篇关于在 watir-webdriver 中可以拖放吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!