DEV Community

Cover image for Automate Adding Publix Coupons
Nazmuz Shakib Pranto
Nazmuz Shakib Pranto

Posted on

Automate Adding Publix Coupons

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/

Publix - Home Page

Step 2

Log into your Publix account
Log into your Publix account

Step 3

Once logged in, click on the "Savings" dropdown and choose the "Digital coupons" link from the navigation menu up top
Digital coupons menu w/in navigation

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!
All digital coupons

Step 5

Ok, now, right click anywhere on the page and click on "Inspect" from the menu
Chrome Inspecter

Step 6

This will open up a whole new section on the right side or the bottom of the page. Either is fine.
Chrome Devtools sidebar

Step 7

Inside the sidebar, click on "Console" from the top menu
Console in Chrome DevTools

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;
    }
  }
})();
Enter fullscreen mode Exit fullscreen mode

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.
Starting automation logs

After all coupons have been added, you should see this message at the end...

Successfully added all coupons logs

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 👋

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (1)

Collapse
 
mikedev2025 profile image
mike Dev

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.

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

Retry later