I've created a function to select the payment randomly (number). when the first selection (number) is not found (try catch) then I want to select another one.
But I always receive:
Failed: Cannot read property 'click'
when sending number 8 and it should select credit cart visa...
What am i doing wrong? The elements are really there and the id is also correct:
CheckoutPage3.prototype.selectPayment = function (number) {
if (number == 1) {
try {
this.elementPaymentPaypal.click().then(function () {
return 1;
}, function (err) {
console.log("payment not found, select new");
this.elementPaymentCreditCard.click();
this.elementCreditVISA.click();
number = 2;
});
}
catch (err) {
console.log('error occured');
}
}
else if (number == 2) {
this.elementPaymentCreditCard.click();
this.elementCreditVISA.click();
number = 2;
} else if (number == 3) {
this.elementPaymentCreditCard.click();
this.elementCreditMasterCard.click();
number = 3;
}
else if (number == 4) {
try {
this.elementPaymentCreditCard.click();
this.elementCreditAmericanExpress.click().then(function () {
number = 4;
}, function (err) {
console.log("payment not found, select new");
this.elementCreditVISA.click();
number = 2;
});
}
catch (err) {
console.log('error occured');
}
}
else {
try {
this.elementPrePayment.click().then(function () {
number = 5;
}, function (err) {
console.log("payment not found, select new");
this.elementPaymentCreditCard.click();
this.elementCreditVISA.click();
number = 2;
});
}
catch (err) {
console.log('error occured');
}
}
};
Aucun commentaire:
Enregistrer un commentaire