0

Considering these simple 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>

By clicking the a element the h1 element is removed.
And next is my js code written in coffeescript:

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

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

casper.run()

However from the screenshots the h1 element was not removed as well.
How do I correctly call the remote function rmH1()?

yakiang
  • 1,608
  • 1
  • 16
  • 17
  • 2
    not duplicate, but might provide some insight: [CasperJS evaluate](http://stackoverflow.com/questions/11864373/casperjs-evaluate) – royhowie Jun 29 '15 at 07:43

1 Answers1

1

There is no such thing as element.remove(). You should use

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

Had you listened to the "page.error" event, you would have seen that remove is not a function.

royhowie
  • 11,075
  • 14
  • 50
  • 67
Artjom B.
  • 61,146
  • 24
  • 125
  • 222