I've been working on automation of user events for some stores but got stuck on cart page for https://shop.advanceautoparts.com/. I've been trying to fire any possible event on input field but it doesn't do same as user inputing data manually. Change event is detected on input but is there any additional events that making "Apply" button usable?
I've been trying with both jQuery and vanilla JS but nothing seems to work.
$(document).ready(function() {
$('input[name="promoCode"]').blur();
$('input[name="promoCode"]').focus();
$('input[name="promoCode"]').attr('value','Example')[0].dispatchEvent(new Event('change', { bubbles: true }));
$('input[name="promoCode"]').val('Example1')[0].dispatchEvent(new Event('change', { bubbles: true }));
$('input[name="promoCode"]').blur();
setTimeout( function () {
$('button[aria-label="Apply"]').removeAttr('disabled');
$('button[aria-label="Apply"]').get(0).dispatchEvent(new MouseEvent('click', { view: window, bubbles: true, cancelable: true }))
}, 100);
setTimeout( function () {
$('button[aria-label="Apply"]').removeAttr('disabled');
$('button[aria-label="Apply"]').get(0).dispatchEvent(new MouseEvent('mousedown', { view: window, bubbles: true, cancelable: true }))
}, 200);
setTimeout( function () {
$('button[aria-label="Apply"]').removeAttr('disabled');
$('button[aria-label="Apply"]').click();
}, 300);
});
The click Event shouldn't be the issue as when I input something maually and fire
$('button[aria-label="Apply"]').click();
then everything is processing normally. Any idea?