2015-06-29 111 views
0

考慮到這些簡單的HTML遙控功能:未能評估casperjs

<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元素被刪除。
而接下來是我的js代碼寫成的CoffeeScript:

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

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

casper.run() 

但是從截圖沒有被移除,以及在h1元素。
如何正確調用遠程功能rmH1()

+2

不重複,但可能會提供一些見解:[CasperJS評估](http://stackoverflow.com/questions/11864373/casperjs-evaluate) – royhowie

回答

1

有沒有這樣的事情element.remove()。您應該使用

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

當初你聽了"page.error"事件,你會看到,removenot a function