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()
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);
})