无法评估 casperjs 中的远程函数

failed to evaluate a remote function in casperjs

考虑这些简单的 html:

<html>
  <body>
    <h1 id='h1'>hello casperjs</h1>
    <a href='javascript: rmH1()'>remove</a>
    <script>
        function rmH1(){
            document.getElementById('h1').remove();
        }
    </script>
  </body>
</html>

通过单击 a 元素,删除 h1 元素。
接下来是我用 coffeescript 编写的 js 代码:

casper = require('casper').create()

casper.start 'file:///Users/username/my.html', ->
    @capture 'before.png'
    @evaluate ->
        rmH1()
    @capture 'after.png'

casper.run()

但是从屏幕截图来看,h1 元素也没有被删除。
如何正确调用远程函数rmH1()?

没有element.remove()这样的东西。你应该使用

var h1 = document.getElementById('h1');
h1.parentNode.removeChild(h1);

如果你听过 "page.error" 事件,你会发现 removenot a function