I want the following Casperjs script to open Google, search a term, and log the title of the page:
var title = ""
var casper = require('casper').create({
verbose: true,
logLevel: 'debug',
pageSettings: {
loadImages: false, // The WebPage instance used by Casper will
loadPlugins: false // use these settings
//userAgent: 'Mozilla/5.0 (Macintosh Intel Mac OS X 10_7_5) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4'
}
})
casper.start('http://google.co.uk/', function() {
// search for 'casperjs' from google form
this.fill('form[action="/search"]', {
q: 'casperjs'
}, true)
})
casper.thenEvaluate(function() {
// aggregate results for the 'casperjs' search
title = document.title
})
casper.log(title, 'warning')
casper.run()
But outputs nothing:
[warning] [phantom]
What am I doing wrong?