Maybe it could help someone. Wrote a simple capybara helper to set values into select2 fields.
See code below.
Maybe it could help someone. Wrote a simple capybara helper to set values into select2 fields.
See code below.
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 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.
Thanks to goodwill with his capybara-select2 gem.