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

时间:2022-06-03 04:04:14

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:

我想使用page.should have_no_content来检查页面是否没有向用户显示标签,这里是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.

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

4 个解决方案

#1


12  

You could use this statement

你可以使用这个声明

find('#account_input').should_not be_visible

#2


3  

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


0  

I found another way to implement should not have

我找到了另一种不应该实现的方法

page.should_not( have_content(arg1))

#4


-1  

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

因此,当我使用page.should have_no_content(“我的帐户”)时,它返回false而不是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.

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

#1


12  

You could use this statement

你可以使用这个声明

find('#account_input').should_not be_visible

#2


3  

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


0  

I found another way to implement should not have

我找到了另一种不应该实现的方法

page.should_not( have_content(arg1))

#4


-1  

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

因此,当我使用page.should have_no_content(“我的帐户”)时,它返回false而不是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.

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