Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8160657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:19:04+00:00 2026-06-06T18:19:04+00:00

How do you test if a div tag has a certain css style? I’m

  • 0

How do you test if a div tag has a certain css style? I’m trying to test if it has display:none; or display:block.

I tried the following but its giving me an error:

it {should have_selector('signup_server_generic_errors', /display:\s*none/)}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:19:07+00:00Added an answer on June 6, 2026 at 6:19 pm

    I’d recommend that instead of trying to locate the css style, you instead write your tests to find the css class name.

    This way you can change the underlying css styling while keeping the class the same and your tests will still pass.

    Searching for the underlying style is brittle. Styles change frequently. Basing your rspecs on finding specific style elements makes your tests more brittle — they’ll be more likely to fail when all you do is change a div’s look and feel.

    Basing your tests on finding css classes makes the tests more robust. It allows them to ensure your code is working correctly while not requiring you to change them when you change page styling.

    In this case specifically, one option may be to define a css class named .hidden that sets display:none; on an element to hide it.

    Like this:

    css:

    .hidden {
      display:none;
    }
    

    html:

    <div class="hidden">HIDE ME!</div>
    

    capybara:

    it {should have_css('div.hidden') }
    

    This capybara just looks for a div that has the hidden class — you can make this matcher more sophisticated if you need.

    But the main point is this — attach styles to css class names, then tie your tests to the classes, not the styles.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<div> <div>test</div> </div> $(div:contains('test')).css('display','none'); I know I am going to kick myself on this.
Example: <div class=test><img src=test.jpg style=display:none; /></div> How to change that with javascript, I know
I am trying to execute a script in a div tag by AJAX. But
<div style=background-color:black> <div style=float:right> Test message </div> <div> This will show 'Test message' with
How could I more simply write #test div, #test span{ .... } is there
I have a div called test and mvc action in the client controller The
How can I test if a mouse is within a given div? I know
In my webpage, there's a div with a class named Test . How can
I have some basic PHP code: $raceramps56[short] = My Test Product; $leftMenu = '<div
<div> <div class="left"> <div align="center" class="node"> <div class="nodeText"> <h2 >test</h2> </div> <div class="node"> <h2>test</h2>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.