Capybara select2 helper

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}")

      find(:xpath, "//body").find("input.select2-input").set(value)
      drop_container = ".select2-results"
      find(:xpath, "//body").find("#{drop_container} li", text: value).click

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.

Need Your Help

Add HTML elements to the current page using PHP

php html dom

So I have the need to dynamically add html content using php which isnt the tricky part but I'm trying to put the HTML into a different location in the document than where the PHP is being run. So ...