【问题标题】:Capybara select2 helper [closed]Capybara select2助手[关闭]
【发布时间】:2014-02-03 13:17:56
【问题描述】:

也许它可以帮助某人。编写了一个简单的 capybara 助手来将值设置到 select2 字段中。

参见下面的代码。

【问题讨论】:

  • 你的问题到底是什么,你想问点什么或告诉别人什么。
  • 分享这个是个好主意,但是为了适应 SE 格式,您应该将其重构为一个问答,两者都由您提供。
  • 只是想和这段代码分享一下。感谢反馈,重构为问答风格

标签: ruby select rspec capybara


【解决方案1】:
module Features
  module CapybaraHelpers
    def select2(value, element_selector)
      select2_container = first("#{element_selector}")
      select2_container.find(".select2-choice").click

      find(:xpath, "//body").find("input.select2-input").set(value)
      page.execute_script(%|$("input.select2-input:visible").keyup();|)
      drop_container = ".select2-results"
      find(:xpath, "//body").find("#{drop_container} li", text: value).click
    end
  end
end

然后在您的代码中调用select2("apple", "#s2id_fruit_id") 之类的东西,水豚将在带有#s2id_fruit_id id 的select2 字段中选择"apple" 值。

感谢goodwill 和他的capybara-select2 gem

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2011-09-27
  • 2015-04-29
  • 1970-01-01
  • 2020-05-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-20
相关资源
最近更新 更多