水豚找不到ID的元素 [英] Capybara can not find element by id
本文介绍了水豚找不到ID的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
水豚在我的黄瓜测试中无法通过ID找到< p>
标签。我 save_and_open_page
时可以看到该元素。但是我无法使用 has_css?
或 find
找到它:
Capybara is not able to find a <p>
tag by it's id in my cucumber test. I'm able to see the element when I save_and_open_page
. But I can't locate it with has_css?
or find
:
pry(#<Object>)> page.html.scan(/notice_sent/).count
=> 1
pry(#<Object>)> page.html.scan(/id=\"notice_sent\"/).count
=> 1
pry(#<Object>)> page.find('#notice_sent')
Capybara::ElementNotFound: Unable to find css "#notice_sent"
from /Users/me/.gem/ruby/2.1.7/gems/capybara-2.4.4/lib/capybara/node/finders.rb:41:in 'block in find'
我缺少什么?
推荐答案
默认情况下,水豚找不到在页面上不可见的元素。您可以尝试
By default Capybara doesn't find elements that are not visible on the page. You can try
page.find('#notice_sent', visible: :all)
看看是否是这种情况。如果是这样,并且您正在测试一个应用程序,则应该执行用户将使该元素可见的任何操作,然后检查其存在。
to see if that's the case. If so, and you're testing an app, then you should perform whatever actions a user would perform that would make that element visible, and then check for its presence.
这篇关于水豚找不到ID的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文