如何在Capybara和ChromeDriver中拖动jQuery滑块手柄? [英] How do I drag a jQuery slider handle from within Capybara and ChromeDriver?
本文介绍了如何在Capybara和ChromeDriver中拖动jQuery滑块手柄?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我能够执行以下代码来移动滑块手柄,但是不会发生浏览器中触发的事件.
I am able to execute the following code to move the slider handle, but the events triggered in the browser are not taking place.
page.execute_script(%Q($('#slider_handicap').slider('values',1,30)))
那正确地将右手柄设置为30,但是我需要它表现得就像我实际上是在握住鼠标并将手柄拖动到30然后释放.
That correctly sets the right handle to 30, but I need it to behave as if I were actually taking the mouse and dragging the handle to 30 then releasing.
推荐答案
我之前扩展了水豚的拖动功能.
它可以将元素移动给定的偏移量.
I extended capybara dragging before.
It can move elements by a given offset.
您可以尝试
module CapybaraExtension
def drag_by(right_by, down_by)
base.drag_by(right_by, down_by)
end
end
module CapybaraSeleniumExtension
def drag_by(right_by, down_by)
resynchronize { driver.browser.action.drag_and_drop_by(native, right_by, down_by).perform }
end
end
::Capybara::Selenium::Node.send :include, CapybaraSeleniumExtension
::Capybara::Node::Element.send :include, CapybaraExtension
然后
page.find('#slider_handicap').drag_by(30, 0)
但是它可能不适合滑块的比例.
But it may not suit the slider's scale.
原始文件是
- Capybara :: Node :: Element#drag_to
- Capybara :: Selenium :: Node#drag_to
- Selenium :: WebDriver :: ActionBuilder drag_and_drop和drag_and_drop_by
- Capybara::Node::Element#drag_to
- Capybara::Selenium::Node#drag_to
- Selenium:: WebDriver::ActionBuilder drag_and_drop and drag_and_drop_by
有几句话要小心.
- 此扩展名可能取决于驱动程序的类型和版本 驱动程序.
- 这种带有拖拽的测试可能会导致维护困难.
- This extension could depend on the type of driver and the version of driver.
- This kind of test with dragging could lead to difficulty of maintainance.
这篇关于如何在Capybara和ChromeDriver中拖动jQuery滑块手柄?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文