[英]Watir - drag and drop not working
I need to test some functionality where I need to drag and drop some UI elements. 我需要测试一些我需要拖放一些UI元素的功能。
I tried to do this on this page http://www.html5rocks.com/en/tutorials/dnd/basics/ : 我尝试在此页面上执行此操作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. 在chrome中,我没有看到任何事情发生。 In firefox, I see the that the mouse button is down, but nothing else happens – the element didn't move. 在Firefox中,我看到鼠标按钮已关闭,但没有其他任何事情发生 - 元素没有移动。 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. 我在mac上使用ruby 1.9.3。 I also tried ruby 2.1.5 on windows and the result was the same. 我也在windows上尝试了ruby 2.1.5,结果是一样的。
Is there a way to drag and drop with watir? 有没有办法用watir拖放?
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.