To test out using JavaScript with PhantomJS I'm trying to write a script that will go to the url "http://phantomjs.org/quick-start.html" and then click on the PhantomJS logo bringing the page to the PhantomJS homepage. My goal is to navigate to a url and successfully click on an html element. However I am getting the error:
TypeError: 'null' is not an object (evaluating 'document.querySelector('img [alt
="PhantomJS"]').click')
phantomjs://webpage.evaluate():3
phantomjs://webpage.evaluate():5
phantomjs://webpage.evaluate():5
Here is my code:
var page = require('webpage').create();
page.open('http://phantomjs.org/quick-start.html', function(status) {
console.log(status);
page.render('websiteBeforeClick.png');
page.evaluate(function() {
document.querySelector('img [alt="PhantomJS"]').click();
});
page.render('websiteAfterClick.png');
phantom.exit();
});
Is my css selector incorrect?