无法评估casperjs中的远程函数

时间:2015-06-29 07:41:04

标签: javascript phantomjs 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()

1 个答案:

答案 0 :(得分:1)

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

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

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

相关问题