Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 497
Samnang Avatar asked Mar 28 '11 01:03

Samnang


2 Answers

You could use this statement

find('#account_input').should_not be_visible
like image 70
Shiv Avatar answered Oct 23 '22 00:10

Shiv


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
like image 45
Samnang Avatar answered Oct 22 '22 23:10

Samnang