However I can't seem to trigger a click on it and I tried everything. I'm definitely selecting the right elements as I can click the button from the Chrome dev console by simply running $('selector').click();
var casper = require('casper').create({
verbose: true,
// logLevel: 'debug',
pageSettings: {
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36'
},
waitTimeout: 10000,
pageSettings: {
loadImages: true,
loadPlugins: true
},
viewportSize: {
width: 1280,
height: 10000
}
});
var password = "pass";
casper.start(url, function() {
this.echo("Loading " + url);
});
casper.then(function() {
this.waitForSelector('.t1-form.signin, .js-password-field, .js-username-field',
function pass() {
this.echo("*** PASS: Form loaded");
// Fill out form
this.fillSelectors('.t1-form.signin', {
"#signin-email": username,
"#signin-password": password
}, true);
// Click login
this.click('.submit.btn');
this.echo("Submitted login...");
},
function fail() {
this.capture("failed1.png");
this.log("Page FAILED to load", "error");
}
);
});
function likeTopTweets(self){
// Just loading a random tweet to test the script with
self.waitForSelector('.ProfileTweet-actionButton.js-actionButton.js-actionFavorite',
function pass() {
self.echo("*** PASS: Loaded page");
this.capture("tweet.png");
self.wait(2000, function(){
if (this.exists('.ProfileTweet-actionButton.js-actionButton.js-actionFavorite')) {
self.echo("Button found! Content:");
self.echo(self.getElementInfo('.ProfileTweet-actionButton.js-actionButton.js-actionFavorite').html);
// I get here and the content of the button is definitely there, and everything appears correctly on the screenshot
// ASSERT , I'm trying stuff here desperately, but nothing seem to work::
var hey = self.evaluate(function() {
var results = ["Hello!"];
results.push( $('.ProfileTweet-actionButton.js-actionButton.js-actionFavorite').html() );
$('.ProfileTweet-actionButton.js-actionButton.js-actionFavorite').click();
results.push( ($( $('.tweet')[0] ).hasClass("favorited") ? "FAVED!!" : "NOT :(") );
$('.ProfileTweet-actionButton.js-actionButton.js-actionFavorite').trigger("click");
results.push( ($( $('.tweet')[0] ).hasClass("favorited") ? "FAVED!!" : "NOT :(") );
$('.ProfileTweet-actionButton.js-actionButton.js-actionFavorite .IconContainer.js-tooltip').click();
results.push( ($( $('.tweet')[0] ).hasClass("favorited") ? "FAVED!!" : "NOT :(") );
$('.ProfileTweet-actionButton.js-actionButton.js-actionFavorite .IconContainer.js-tooltip').trigger("click");
results.push( ($( $('.tweet')[0] ).hasClass("favorited") ? "FAVED!!" : "NOT :(") );
$('.ProfileTweet-actionButton.js-actionButton.js-actionFavorite .IconContainer.js-tooltip .Icon--favorite').click();
results.push( ($( $('.tweet')[0] ).hasClass("favorited") ? "FAVED!!" : "NOT :(") );
$('.ProfileTweet-actionButton.js-actionButton.js-actionFavorite .IconContainer.js-tooltip .Icon--favorite').trigger("click");
results.push( ($( $('.tweet')[0] ).hasClass("favorited") ? "FAVED!!" : "NOT :(") );
return results;
});
self.echo(hey);
} else {
this.echo('Didnt exist :(');
}
// self.evaluate(function(){
// $('.js-stream-item.stream-item .ProfileTweet-actionButton.js-actionFavorite').each(function(){
// $(this).click();
// });
// });
});
},
function fail() {
self.log("Hashtags not loaded...", "error");
}
);
});
}
casper.then(function() {
var self = this;
// Wait for Logo to load
self.waitForSelector('.Icon--bird',
function pass() {
self.echo("*** PASS: Logged in, page loaded");
// Entering main automation logic
likeTopTweets(self);
},
function fail() {
self.capture("failed2.png");
self.log("Page FAILED to load", "error");
}
);
});
function restartLogic(){
likeTopTweets();
}
// Restart on error
casper.on('error', function(msg, backtrace) {
restartLogic();
});
// Restart on end
casper.run(function() {
restartLogic();
});