水豚找不到语义用户界面的选择框

bob*_*lin 4 ruby-on-rails capybara capybara-webkit semantic-ui

我将capybaracapybara-webkitSemantic-ui结合使用,但它似乎无法显示下拉菜单,因为<select>element是隐藏的:

# feature_spec.rb
select 'option1', from: 'Options'

$ rspec feature_spec.rb

Capybara::ElementNotFound:
  Unable to find select box "Options"
Run Code Online (Sandbox Code Playgroud)

您对此有可行的解决方案吗?

bob*_*lin 5

我创建了这个帮助器:

# for Semantic-ui dropdown
def select_from_dropdown(item_text, options)
  # find dropdown selector
  dropdown = find_field(options[:from], visible: false).first(:xpath,".//..")
  # click on dropdown
  dropdown.click
  # click on menu item
  dropdown.find(".menu .item", :text => item_text).click
end

# in spec
select_from_dropdown 'option1', from: 'Options'
Run Code Online (Sandbox Code Playgroud)

希望对您有所帮助:-)