Capybara找不到Semantic-ui的选择框

时间:2016-01-21 10:44:12

标签: ruby-on-rails capybara semantic-ui capybara-webkit

我将 capybara capybara-webkit Semantic-ui 一起使用,但是接下来这些下拉列表无法开箱即用,因为隐藏了<select>元素:

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

$ rspec feature_spec.rb

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

你有解决方案吗?

3 个答案:

答案 0 :(得分:4)

我已经创建了这个帮手:

# 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'

我希望它有所帮助: - )

答案 1 :(得分:0)

你也可以这样做:

execute_script('$("#Options").dropdown("set selected", "option1");')

execute_script允许您在测试中运行脚本。它使用semantic-ui方法从下拉列表中选择所需的选项。

答案 2 :(得分:0)

经过两天的搜索和阅读,这篇文章是其中几篇有用的文章之一。希望这可以帮助其他人!

我创建了一些类似的方法,请改名。我更改了它。

TRIM(LEADING '0' FROM colname)

我还引用了this。 还要尝试等待,睡觉和看得见:false

相关问题