Background (feel free to skip)
Ok, let me cut to the chase... I am a software engineer by profession, so I like to use my skills to automate as many of the repeatable tasks as I can to make my life a little easier. I did this very exact thing for auto-adding CVS coupons before as shown in this post: Automate Adding CVS Coupons.
This post is the same as the CVS one, but for Publix users, so for those who use Publix couping frequently, hope this helps a little bit.
With this guide, you will no longer have to manually click on each “Clip coupon” button, rather you will just need to run a script which you can find at the bottom of this post and it will auto-add all the clippable coupons for you.
Anyways, let's get started.
Step 1
Open
Google Chrome
browser, go over to https://www.publix.com/
Step 2
Step 3
Once logged in, click on the "Savings" dropdown and choose the "Digital coupons" link from the navigation menu up top
Step 4
Now, you should be able to see all of your digital coupons within Publix. There are a lot of coupons here and having to add each one of these manually would be a pain for sure. THIS is the part we want to automate!
Step 5
Ok, now,
right click
anywhere on the page and click on "Inspect" from the menu
Step 6
This will open up a whole new section on the right side or the bottom of the page. Either is fine.
Step 7
Step 8
Now, here comes the MAIN part: copy over this piece of code and paste it right after the
>
sign
(async () => {
console.log("🚀 Starting coupon clipping automation...");
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const clickLoadMoreBtn = () => {
const button = document.querySelector('[data-qa-automation="button-Load more"]');
if (button) {
console.log("🔄 Clicking 'Load More' button...");
button.dispatchEvent(new Event('mousedown'));
button.dispatchEvent(new Event('mouseup'));
button.dispatchEvent(new Event('click'));
}
};
const findAllClippableCoupons = () => {
return document.querySelectorAll('[data-qa-automation="button-Clip coupon"]');
};
while (true) {
const clippableCoupons = findAllClippableCoupons();
const totalCoupons = clippableCoupons.length;
if (totalCoupons === 0) {
console.log("✅ No more coupons left to clip 🥳");
break;
}
console.log(`🛍️ Total coupons to clip: ${totalCoupons}`);
for (const [index, coupon] of clippableCoupons.entries()) {
console.log(`🎯 Clipping coupon ${index + 1} of ${totalCoupons}...`);
coupon.scrollIntoView({ behavior: 'smooth', block: 'center' });
await wait(100);
coupon.click();
const couponsLeft = totalCoupons - (index + 1);
await wait(75);
}
console.log("📜 Hold up! Checking for more coupons...");
window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });
await wait(2000);
const loadMoreBtn = document.querySelector('[data-qa-automation="button-Load more"]');
if (loadMoreBtn !== null) {
console.log("🔄 More coupons detected! Loading more ...");
clickLoadMoreBtn();
await wait(3000);
} else {
console.log("🎉 All coupons have been clipped! Enjoy your savings! 🎉");
break;
}
}
})();
Step 9
Then, press
ENTER
to run the script and watch some magic happen in the background. Notice all the coupons being automatically clicked and added for you.
After all coupons have been added, you should see this message at the end...
Step 12
That's it, now all the coupons should be added to your account. Note, if at any time, you make any mistakes along the way while following these steps, just refresh the page and rerun the script above.
Let me know if you found this helpful. Hope I was able to save at least a little bit of your time through this automation script... until next time 👋
Top comments (1)
Great job!!
I really appreciate the "Hold up! Checking for more coupons..." effort for the "Load More" automation. 279 coupons clipped today, page after page.