capybara: page.should have_no_content doesn't work correctly for display:none element

隐身守侯 提交于 2019-11-27 18:11:53

问题


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>

So when I use page.should have_no_content("My Account"), it returns false instead of true.


回答1:


You could use this statement

find('#account_input').should_not be_visible



回答2:


I found a solution using:

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



回答3:


I found another way to implement should not have

page.should_not( have_content(arg1))




回答4:


So when I use page.should have_no_content("My Account"), it returns false instead of true.

It should be false. Think about it this way: if your page does have the content "My account", then have_content would return True, thus have_no_content should return False. And the reason - it is not true to say that the HTML does not have the content "My account" in it. Thus, it is False.



来源:https://stackoverflow.com/questions/5453729/capybara-page-should-have-no-content-doesnt-work-correctly-for-displaynone-el

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!