水豚:page.should have_no_content 不能正常工作 display:none 元素 [英] capybara: page.should have_no_content doesn't work correctly for display:none element
本文介绍了水豚:page.should have_no_content 不能正常工作 display:none 元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用 page.should have_no_content 来检查页面是否没有向用户显示标签,这里是 HTML:
I would like to use page.should have_no_content to check if the page doesn't display the label to user, here what it is in HTML:
<li id="account_input" style="display: none;">
<label for="account_name">My Account</label>
...
</li>
所以当我使用 page.should have_no_content("My Account") 时,它返回 false 而不是 true.
So when I use page.should have_no_content("My Account"), it returns false instead of true.
推荐答案
我找到了 解决方案 使用:
Then /^"([^"]+)" should not be visible$/ do |text|
paths = [
"//*[@class='hidden']/*[contains(.,'#{text}')]",
"//*[@class='invisible']/*[contains(.,'#{text}')]",
"//*[@style='display: none;']/*[contains(.,'#{text}')]"
]
xpath = paths.join '|'
page.should have_xpath(xpath)
end
这篇关于水豚:page.should have_no_content 不能正常工作 display:none 元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文