简体   繁体   中英

How do I get the list of stylesheets from CasperJS?

How do I get the list of stylesheets from CasperJS? I want what 'document.styleSheets' returns in Chrome.

eg:

StyleSheetList {0: CSSStyleSheet, 1: CSSStyleSheet, 2: CSSStyleSheet,3: CSSStyleSheet, 4: CSSStyleSheet, 5: CSSStyleSheet, 6: CSSStyleSheet, 7: CSSStyleSheet, 8: CSSStyleSheet, 9: CSSStyleSheet, 10: CSSStyleSheet, 11: CSSStyleSheet, 12: CSSStyleSheet, length: 13, item: function}

You access the style sheet in the same way, you would access it in Chrome, but before you do it, you have to get it from the page context.

var css = casper.evaluate(function(){
    return document.styleSheets;
});
casper.echo(css[0].href); // href of first stylesheet

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM