使用Capybara,我需要断言表单元素不存在,例如,"那么我不应该看到"Username"文本字段".如果找不到元素,find会抛出一个异常,这是我想到的最好的方法.有更好的办法吗?
Then /^I should not see the "([^\"]+)" ([^\s]+) field$/ do |name, type|
begin
# Capybara throws an exception if the element is not found
find(:xpath, "//input[@type='#{type}' and @name='#{name}']")
# We get here if we find it, so we want this step to fail
false
rescue Capybara::ElementNotFound
# Return true if there was an element not found exception
true
end
end
我是水豚的新手,所以我可能错过了一些明显的东西.