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 7939887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:13:56+00:00 2026-06-03T23:13:56+00:00

How can i Assert that the CSS for a page has successfully loaded and

  • 0

How can i Assert that the CSS for a page has successfully loaded and applied its styles in Watin 2.1?

  • 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-03T23:13:57+00:00Added an answer on June 3, 2026 at 11:13 pm

    After doing some research and writing up my answer, I stumbled upon this link that explains everything you need to know about CSS, when it is loaded and how you can check for it.

    The link provided explains it so well, in fact, that I’m adding some quotes from it for future reference.
    If you’re curious, my answer was going to be #2 and a variation of #4.

    When is a stylesheet really loaded?

    …

    With that out of the way, let’s see what we have here.

    // my callback function 
    // which relies on CSS being loaded function
    CSSDone() {
        alert('zOMG, CSS is done');
    };
    
    // load me some stylesheet 
    var url = "http://tools.w3clubs.com/pagr/1.sleep-1.css",
        head = document.getElementsByTagName('head')[0],
        link = document.createElement('link');
    
    link.type = "text/css"; 
    link.rel = "stylesheet";
    link.href = url;
    
    // MAGIC 
    // call CSSDone() when CSS arrives
    head.appendChild(link);
    

    Options for the magic part, sorted from nice-and-easy to ridiculous

    1. listen to link.onload
    2. listen to link.addEventListener(‘load’)
    3. listen to link.onreadystatechange
    4. setTimeout and check for changes in document.styleSheets
    5. setTimeout and check for changes in the styling of a specific element you create but style with the new CSS

    5th option is too crazy and assumes you have control over the content of the CSS, so forget it. Plus it checks for current styles in a timeout meaning it will flush the reflow queue and can be potentially slow. The slower the CSS to arrive, the more reflows. So, really, forget it.

    So how about implementing the magic?

    // MAGIC 
    
    // #1   
    link.onload = function () {
        CSSDone('onload listener');
    };   
    
    // #2   
    if (link.addEventListener) {
        link.addEventListener('load', function() {
            CSSDone("DOM's load event");
        }, false);   
    };   
    
    // #3   
    link.onreadystatechange = function() {
        var state = link.readyState;
        if (state === 'loaded' || state === 'complete') {
            link.onreadystatechange = null;
            CSSDone("onreadystatechange");
        }   
    };
    
    // #4   
    var cssnum = document.styleSheets.length;
    var ti = setInterval(function() {
        if (document.styleSheets.length > cssnum) {
            // needs more work when you load a bunch of CSS files quickly
            // e.g. loop from cssnum to the new length, looking
            // for the document.styleSheets[n].href === url
            // ...
    
            // FF changes the length prematurely :(
            CSSDone('listening to styleSheets.length change');
            clearInterval(ti);
        }   
    }, 10);
    
    // MAGIC ends
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In NUnit, I can write either Assert.That(5, Is.EqualTo(5)); or Assert.AreEqual(5, 5); Is there any
How can I write a test to assert that the action new is rendered?
How can I assert that a variable satisfies any one of two values in
Is there a way I can assert that two constant expressions are equal at
I have certain page-specific js and css files that I either: Don't want running
Is there a way that you can assert whether or not a variable is
I have a bookmarklet that can be loaded on any website. It works like
If I want to make a rule dynamic so i can use assert after
I was wondering, I am aware you can use assert to add facts or
Can you tell me if there's a way to dis- and enable junit.framework.Assert commands

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.