capybara:page.should has_no_content不能正确工作display:none元素 [英] capybara: page.should have_no_content doesn't work correctly for display:none element

查看:175
本文介绍了capybara:page.should has_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(我的帐户),它返回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

这篇关于capybara:page.should has_no_content不能正确工作display:none元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆