0

When the jQuery code $('.reply_button').click() for clicking a button is executed on the Chrome browser, a menu popups as expected. However when the same jQuery code is executed within a this.evaluate in CasperJS, the webpage shows a loading screen instead.

Why is the page reacting differently, and how can we get the popup the way we would when using the Chrome browser?

CasperJS Code

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

casper.options.pageSettings = {
    loadImages:  true, 
    loadPlugins: false,
    userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X)'
}

casper.start("http://raleigh.craigslist.org/apa/5167043093.html", function() {
    this.evaluate(function() {
        $('.reply_button').click()
    })
})


casper.wait(5000, function() {
     this.capture('1.png')
})

casper.run()

Screencapture by CasperJS enter image description here

Screencapture by Chrome enter image description here


Output containing the debug and ResourceError

[info] [phantom] Starting...
[info] [phantom] Running suite: 3 steps
[debug] [phantom] opening url: http://raleigh.craigslist.org/apa/5167043093.html, HTTP GET
[debug] [phantom] Navigation requested: url=http://raleigh.craigslist.org/apa/5167043093.html, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "http://raleigh.craigslist.org/apa/5167043093.html"
[debug] [phantom] Navigation requested: url=http://www.craigslist.org/static/localstorage.html?v=51a29e41f8e978141e4085ed4a77d170, type=Other, willNavigate=true, isMainFrame=false
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step anonymous 2/3 http://raleigh.craigslist.org/apa/5167043093.html (HTTP 200)
[info] [phantom] Step anonymous 2/3: done in 1264ms.
[info] [phantom] Step _step 3/3 http://raleigh.craigslist.org/apa/5167043093.html (HTTP 200)
[info] [phantom] Step _step 3/3: done in 1279ms.
ResourceError: {
    "errorCode": 6,
    "errorString": "SSL handshake failed",
    "id": 28,
    "url": "https://www.google.com/recaptcha/api.js?onload=gRecaptchaCallback&render=explicit&_=1439307138317"
}
[info] [phantom] wait() finished waiting for 5000ms.
[debug] [phantom] Capturing page to /Users/x/test/1.png
[info] [phantom] Capture saved to /Users/x/test/1.png
[info] [phantom] Done 3 steps in 6523ms
Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///usr/local/lib/node_modules/casperjs/bin/bootstrap.js. Domains, protocols and ports must match.

Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///usr/local/lib/node_modules/casperjs/bin/bootstrap.js. Domains, protocols and ports must match.

Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///usr/local/lib/node_modules/casperjs/bin/bootstrap.js. Domains, protocols and ports must match.

Trying a native click instead of synthetic click

Still triggering captcha

casper.start("http://raleigh.craigslist.org/apa/5167043093.html", function() {
    var rect = casper.page.evaluate(function() {
        return $('.reply_button')[0].getBoundingClientRect();
    });
    casper.page.sendEvent('click', rect.left + rect.width / 2, rect.top + rect.height / 2);
})
Nyxynyx
  • 61,411
  • 155
  • 482
  • 830
  • What 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)). Maybe there are errors. – Artjom B. Aug 11 '15 at 15:08
  • @ArtjomB. Updated post with the details. What may have caused the SSL error? Why do you think CasperJS/PhantomJS triggers the recaptcha check, but not when using the actual Chrome browser? – Nyxynyx Aug 11 '15 at 15:35
  • Seems like it. Maybe it is sufficient to use a [native click](http://stackoverflow.com/a/24026636/1816580) event instead of a synthetic jQuery click. `page` is available as `casper.page` in CasperJS. – Artjom B. Aug 11 '15 at 15:44
  • @ArtjomB. Tried your suggestion of using the native click (updated post with new code) but still triggering the recaptcha and encountering the failed SSL handshake... – Nyxynyx Aug 11 '15 at 15:49
  • Try use `--ssl-protocol=any` and `--ignore-ssl-errors` parameters on command... – Diego Borges Aug 12 '15 at 20:30

0 Answers0