Ruby on rails Capybara找不到语义ui的选择框
我将capybara与capybara webkit和Semantic ui一起使用,但它指出,下拉列表无法开箱即用,因为元素是隐藏的:Ruby on rails Capybara找不到语义ui的选择框,ruby-on-rails,capybara,semantic-ui,capybara-webkit,Ruby On Rails,Capybara,Semantic Ui,Capybara Webkit,我将capybara与capybara webkit和Semantic ui一起使用,但它指出,下拉列表无法开箱即用,因为元素是隐藏的: # feature_spec.rb select 'option1', from: 'Options' $ rspec feature_spec.rb Capybara::ElementNotFound: Unable to find select box "Options" 您对此有有效的解决方案吗?我创建了此帮助程序: # for Semanti
# feature_spec.rb
select 'option1', from: 'Options'
$ rspec feature_spec.rb
Capybara::ElementNotFound:
Unable to find select box "Options"
您对此有有效的解决方案吗?我创建了此帮助程序:
# 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'
我希望它有帮助:-您也可以这样做:
execute_script('$("#Options").dropdown("set selected", "option1");')
执行脚本允许您在测试中运行脚本。它使用语义ui方法从下拉列表中选择所需的选项。经过两天的搜索和阅读,本文是其中一篇有用的文章。希望这能帮助其他人 我创建了一些这样的方法,请原谅命名..我更改了它
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
我还提到。
还可以尝试等待、睡眠和可见:false欢迎使用StackOverflow!当您发布任何代码时,您应该对其进行描述,以便不仅询问者,而且整个社区都能够轻松理解您的代码。谢谢!我认为这段代码很容易解释!无论如何,我编辑了它,以防人们需要它。