简体   繁体   中英

failed to evaluate a remote function in casperjs

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() ?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM