I'm trying to create a phantom script to automate testing of the following form:
My script completes the required fields correctly and then clicks the button that should submit the form, unfortunately no matter what I have tried it won't submit the form and display the next page.
I've confirmed that the click on the button is firing, as without completing the mandatory fields, I see in a screenshot of the page that the validation has fired. (see screenshot attached)
I've commented below all the click/submit options that I've tried and the one that appears to trigger the form validation but doesn't submit the form and display the next page.
var page = require('webpage').create();
page.open("https://travel.tescobank.com/", function(status) {
var currentLocation = page.evaluate(function() {
return window.location.href;
});
// click the button for single trip
var tripType = page.evaluate(function() {
var trip = $("#single-trip-radio").trigger("click");
return (trip != null);
});
// enter value in dropdown
var countrySearch = page.evaluate(function() {
var country = $("#countrySearch").val("France");
return (country != null);
});
var datePickerOne = page.evaluate(function() {
var datePicker1 = $("#stFromdate").val("01-11-2017");
return $("#stFromdate");
});
var datePickerTwo = page.evaluate(function() {
var datePicker2 = $("#stTodate").val("08-11-2017");
return $("#stTodate").val();
});
var numberOfTravellers = page.evaluate(function() {
var number = $("#couple").trigger("click");
return $("#couple").val();
});
var firstName = page.evaluate(function() {
var fname = $("#fName").val("Test");
return $("#fName").val();
});
var secondName = page.evaluate(function() {
var sname = $("#sName").val("Test");
return $("#sName").val();
});
var dateOfBirth = page.evaluate(function() {
var dob = $("#phDOB").val("11-10-1977");
return $("#phDOB").val();
});
var dateOfBirth2 = page.evaluate(function() {
var dob2 = $("#ydob1").val("11-10-1977");
return $("#ydob1").val();
});
var postcode = page.evaluate(function() {
var pc = $("#postcode").val("SS1 2AA");
return $("#postcode").val();
});
var email = page.evaluate(function() {
var em = $("#emailaddr").val("test@test.com");
return $("#emailaddr").val();
});
//various attempts to submit the form
//var submitForm = page.evaluate(function() {
//does not submit
//$("#aboutYouForm").submit();
//does not submit
//var elementPosition = $("#aboutYouSubmit").offset();
//page.sendEvent('click', elementPosition.left + 1, elementPosition.top + 1);
//does not submit
//return $("#aboutYouSubmit").val();
//});
// this click on the button does fire the form validation but doesn’t seem to submit the form
var submitForm = page.evaluate(function() {
var theForm = $("#aboutYouSubmit").trigger("click");
return (theForm != null);
}
}
I can't see that there's any errors causing it not to submit the form correctly, it just stays on the same screen without any validation errors as far as I can see from the output. Any help appreciated.