【发布时间】:2015-05-03 01:15:19
【问题描述】:
我想确定存在id="foo" 的input 字段:
<input id="foo" ... />
我还想确保在某些情况下,另一个带有id="bar" 的input 字段不存在。
【问题讨论】:
标签: ruby-on-rails forms capybara integration-testing
我想确定存在id="foo" 的input 字段:
<input id="foo" ... />
我还想确保在某些情况下,另一个带有id="bar" 的input 字段不存在。
【问题讨论】:
标签: ruby-on-rails forms capybara integration-testing
存在:
expect(page).to have_css('#bar')
不存在:
expect(page).to have_no_css('#bar')
注意:不要使用expect(page).to_not have_css,因为它会等待你的元素出现。
expect 和否定形式如has_no_selector? 和not has_selector? 的解释可以在Capybara's Asynchronous JavaScript documentation 中找到。
【讨论】:
要确定特定的input 字段是否存在,请使用:
assert has_xpath?("//input[@id='foo']")
要确定特定的 input 字段是否不存在,请使用以下之一:
assert has_no_xpath?("//input[@id='bar']")
refute has_xpath?("//input[@id='bar']")
【讨论】: