capybara:page.should have_no_content对display:none元素无法正常工作

我想使用page.should have_no_content来检查页面是否没有向用户显示标签,这里是HTML中的内容:

  • ...
  • 因此,当我使用page.should have_no_content(“我的帐户”)时,它返回false而不是true。

    你可以使用这个声明

     find('#account_input').should_not be_visible 

    我找到了一个解决方案 :

     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_not(have_content(arg1))

    因此,当我使用page.should have_no_content(“我的帐户”)时,它返回false而不是true。

    应该是假的。 可以这样考虑:如果您的页面确实包含“我的帐户”内容,那么has_content将返回True,因此have_no_content应返回False。 原因是 – 并不是说​​HTML中没有“我的帐户”内容。 因此,这是假的。