您可以使用selenium-
webdriver的动作构建器。但是,firefoxdriver中似乎存在一个错误,目前阻止该错误运行(可能是问题4863)。
这是使用Chrome的“ jQuery可选”页面的工作示例:
require 'capybara'require 'capybara/dsl'include Capybara::DSL#Use selenium-webdriver with chromeCapybara.register_driver :selenium do |app| Capybara::Selenium::Driver.new(app, :browser => :chrome)endCapybara.current_driver = :selenium#Go to the JQuery Selectable example pageCapybara.app_host = 'http://jqueryui.com/selectable/'page.visit('')#The controls are in a frame, so need to switch to itwithin_frame 0 do #Create a selenium-webdriver action builder builder = page.driver.browser.action #Hold control key down builder.key_down(:control) #Click all elements that you want, in this case we click all lis #Note that you can retrieve the elements using capybara's # standard methods. When passing them to the builder # make sure to do .native elements = page.all('ol#selectable li') elements.each do |e| builder.click(e.native) end #Release control key builder.key_up(:control) #Do the action setup builder.performend
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)