Riddler Riddler - 1 month ago 16
AngularJS Question

Angular material select for capybara

Can I make select in RoR RSpec + Capybara?
Usually i use:

select 'something', from: 'select_name'


But for angular's
md-select
is doesn't work.
Capybara show error:

Capybara::ElementNotFound: Unable to find select box "select_id"

Answer

I simple add a custom md_select method to Capybara.

def md_select name, from: ''
  puts 'md_select `from:` param is required. For example `md_select select_value, from: select_name`' if from.blank?

  find(:xpath, "//md-select[@name='#{from}']").click
  find(:xpath, "//md-select-menu/md-content/md-option/div[text()='#{name}']").click
end

And now we can use it in RSpec:

md_select select_value, from: 'select_name'