Capybara select2 helper [closed]
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Maybe it could help someone. Wrote a simple capybara helper to set values into select2 fields. See code below. 回答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 Then in