本文介绍了如何从 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.
推荐答案
我之前扩展了capybara拖拽.
它可以将元素移动给定的偏移量.
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 和 ChromeDriver 中拖动 jQuery 滑块句柄?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!