Javascript CasperJS在回调动态脚本/链接调用时未正确触发

Javascript CasperJS在回调动态脚本/链接调用时未正确触发,javascript,casperjs,Javascript,Casperjs,我对Casper JS和示例html页面有问题 我动态添加的外部引导调用的onLoad事件不会在casper端触发/处理。在我的示例中,屏幕截图永远不会是红色的,但是如果我从浏览器加载页面,那么页面看起来确实是红色的 <html> <head> <title>Title of the document</title> </head> <body> <script type="text/javascript">

我对Casper JS和示例html页面有问题

我动态添加的外部引导调用的onLoad事件不会在casper端触发/处理。在我的示例中,屏幕截图永远不会是红色的,但是如果我从浏览器加载页面,那么页面看起来确实是红色的

<html>
<head>
<title>Title of the document</title>
</head>
<body>
<script type="text/javascript">
    var s = document.createElement("link");
    s.href = "http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css";
    s.rel = "stylesheet";
    s.type = "text/css";
    document.body.appendChild(s);
    s.onload = function(){
        document.body.style.backgroundColor = "red";
    };
</script>
</body>
</html>
我遗漏了什么吗?

PhantomJS(v1.9.7),CasperJS的底层无头浏览器,具有与Chrome 13相同的功能,Chrome 13似乎不支持
链接
元素上的
onload
。如果你需要它,你可能会找到一些解决办法

否则,以下代码将执行您想要的操作:

casper.start('test.html');

casper.waitForResource(/css/, function(){
    this.evaluate(function(){
        document.body.style.backgroundColor = "red";
    });
    this.capture("debug.png");
});
您可以使用
--engage=slimerjs
从已安装的firefox运行gecko引擎

不相干的<代码>链接
元素更适合
头部
而不是
正文

casper.start('test.html');

casper.waitForResource(/css/, function(){
    this.evaluate(function(){
        document.body.style.backgroundColor = "red";
    });
    this.capture("debug.png");
});