-1

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.

Piotr Kruczek
  • 2,384
  • 11
  • 18
  • Which PhantomJS version do you use? Please register to the `resource.error`, `page.error`, `remote.message` and `casper.page.onResourceTimeout` events ([Example](https://gist.github.com/artjomb/4cf43d16ce50d8674fdf#file-2_caspererrors-js)). Maybe there are errors. – Artjom B. Jan 12 '16 at 13:58
  • That's better, have you registered to the error events to see if for example some JS couldn't be executed? Also, it's important to know which PhantomJS version you're using. – Artjom B. Jan 12 '16 at 14:36
  • Thank you very much. Just started using this today, too rushed to think of proper debugging. – Piotr Kruczek Jan 12 '16 at 14:59

1 Answers1

0

Wow, thank you @Artjom B.

The issue was the standard phantomjs ssl problem, the site was loading jquery using https, subscribing to resource.error helped me find that.

The solution was to run casperjs with --ignore-ssl-errors=true flag.

Community
  • 1
  • 1
Piotr Kruczek
  • 2,384
  • 11
  • 18