CasperJS (also phantomjs) comes with an evaluate()
method that takes a function inside which we could access the current page DOM context . It is recently that I understood how eval
works wherever it be. Angular also comes with the angular.element(<element>).scope()
that lets you access the scope of that particular element . In my case I wanted to change the start_time
and end_time
of a booking before clicking submit .
casper.evaluate(function () {
var scope = angular.element('booking-element').scope()
var bookingForm = scope.booking;
bookingForm.start_time = "2017-09-05 12:00";
bookingForm.end_time = "2017-09-05 16:00"
scope.$apply();
});
A casper.click('.submit-button')
should be submit the button for you with the updated values .