0

I'm trying to learn phantomjs for automatically getting data from a site that's now protected with javascript.

I need to click on a link; as per this question I tried to add the custom function "eventFire" to my phantomjs file, as per this post. But no matter what I've tried it outputs ReferenceError: Can't find variable: eventFire

Could someone please tell me the proper way to do this? because I'm not seeing it, thank you.

I tried copying the function exactly and that didn't work, so I tried this also with the same result:

eventFire = function(el, etype){
  if (el.fireEvent) {
    (el.fireEvent('on' + etype));
  } else {
    var evObj = document.createEvent('Events');
    evObj.initEvent(etype, true, false);
    el.dispatchEvent(evObj);
  }
}
Community
  • 1
  • 1
Joe T
  • 2,300
  • 1
  • 19
  • 31

1 Answers1

1

If you were using page.evaluate, you can pass the function as an argument.

page.evaluate(function(eventFire_fn) {
    // click your 'element'
    eventFire_fn(element, 'click');
}, eventFire);
Jiangwei Yu
  • 609
  • 7
  • 7