问题
I use capybara with capybara-webkit and Semantic-ui, but it seams that dropdowns doesn't work out of box, because <select>
element is hidden:
# feature_spec.rb
select 'option1', from: 'Options'
$ rspec feature_spec.rb
Capybara::ElementNotFound:
Unable to find select box "Options"
Do you have working solutions for this?
回答1:
I've created this helper:
# 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'
I hope it helps :-)
回答2:
You could also do this:
execute_script('$("#Options").dropdown("set selected", "option1");')
execute_script allows you to run scripts in your tests. It uses the semantic-ui method to select the option that you want from the dropdown.
回答3:
After two days of searching and reading, this article was amongst one of a few that was helpful. Hopefully, this can help someone else!
I created a few methods like so, excuse the naming..I changed it.
def some_dropdown(id, text)
dropdown = find(id).click
dropdown.first('option', text: text).select_option
end
def select_form
within 'content#id' do
some_dropdown('#id', text)
click_link_or_button 'Submit'
end
end
I also referenced this. Also try waiting, sleep and visible: false
来源:https://stackoverflow.com/questions/34921509/capybara-cant-find-select-box-for-semantic-ui