I've been working on a little script using casperjs
that could parse a simple page with elements appended by submitting an AJAX form. How could I do that?
This doesn't seem to work (coffeescript):
getLinks = ->
links = document.querySelectorAll('a')
Array::map.call links, (e) ->
e.getAttribute 'href'
casper = require('casper').create()
casper.start 'somepage', ->
@fill '#some-form', {text: 'hello'}, true
# appends an element on success
casper.then ->
links = @evaluate(getLinks)
@echo links[0]
casper.run ->
@exit()
EDIT:
Submitting the form using casper follows the action of the form, meaning that it redirects to an empty page with a json response instead of catching it in ajax:success
like it does when I do it manually via a browser. The form has a post
method and is overriten in javascript to send an AJAX request and append an element to the DOM on success. I've tried changing javascriptEnabled
setting, but it is true
by default.
TL;DR Submitting the form using casper doesn't trigger javascript, while doing it manually (or in browser console) does.