Skip to content

Instantly share code, notes, and snippets.

@lucashungaro
Last active January 27, 2017 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucashungaro/6596462 to your computer and use it in GitHub Desktop.
Save lucashungaro/6596462 to your computer and use it in GitHub Desktop.
Triggering an autocomplete select box with Capybara and Turnip
# on spec/helpers
module FormHelper
def fill_in_autocomplete(selector, value)
page.execute_script %Q{$('#{selector}').focus().val('#{value}').keydown()}
end
def choose_autocomplete(text)
find('ul.ui-autocomplete').should have_content(text)
page.execute_script("$('.ui-menu-item:contains(\"#{text}\")').find('a').trigger('mouseenter').click()")
end
end
# on spec_helper.rb, inside Rspec.configure block
config.include FormHelper, :type => :feature
#Calling these:
fill_in_autocomplete '#produto_search', @product.model_name
sleep 1
choose_autocomplete(@product.model_name)
@DannySantos
Copy link

Doesn't work for me, it doesn't trigger the AJAX call that collects the results unless I physically click on the input field. Cannot find a solution to this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment