水豚select2助手 [英] Capybara select2 helper

查看:126
本文介绍了水豚select2助手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许可以帮助某人.编写了一个简单的水豚助手,将值设置到select2字段中.

Maybe it could help someone. Wrote a simple capybara helper to set values into select2 fields.

请参见下面的代码.

推荐答案

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"值.

Then in your code just call something like select2("apple", "#s2id_fruit_id") and capybara will select "apple" value in select2 field with #s2id_fruit_id id.

感谢善意和他的 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆