Automate Adding CVS Coupons
Tags: cvs, coupons, automate
Published: 2022-03-12 18:14:00

## Background (feel free to skip)

Ok, I understand this post is kind of weird OR may not relate to everybody, but stick with me here... let me explain.

I am a Software Engineer by day and as part of my profession, I like to program or code to automate any repeatable tasks that I have to do regularly.

This is where CVS coupons come into play. I generally find myself shopping at CVS Pharmacy often and they have a program called ExtraCare. It sends you, the customer, coupons on a daily or weekly basis to show appreciation and help you to save a few dollars here and there. 

_Note: CVS did not pay me to write this post, I just found this useful and thought maybe, just maybe, others might find it useful._

Anyways, let's get started.

With this guide, you will no longer have to manually click on each “Send to Card” button to auto add ExtraCare coupons for your CVS account.

---

> **Who is this for?**

If all of these conditions apply to you, you might find this automation useful:
- Are you a regular customer of CVS Pharmacy?
- Do you have ExtraCare with CVS and use coupons regularly?
- Do you hate having to manually add coupons every day or week?

---

## Let's Get Started

### Step 1

> Open `Google Chrome` browser, go over to https://www.cvs.com/

![CVS Pharmacy - Home](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q2133nplp4z475dn2k3d.png)

### Step 2

> Log into your CVS account

![CVS Pharmacy - Login](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4vl4eua2mcwz7ifhfrug.png)

### Step 3

> Once logged in, click on the "ExtraCare" link from the top navigation bar

![ExtraCare Link](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vs7ven7eposnn6le0o0z.png)

### Step 4

> Now, you should be able to see all of your coupons provided through ExtraCare (specifically for you). There are a lot of coupons here and having to manually add each one of these is a pain. **THIS is the part we want to automate!**

![All CVS Coupons](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iuqreoviir8o1379pqae.png)

### Step 5

> First thing we want to do is scroll down to the bottom of the page. Notice, more and more coupons are being loaded as you scroll to the bottom. Keep scrolling until no more coupons are loaded.

![Bottom of Coupons Page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p3ey9y4ng1rw2gzwccqe.png)

### Step 6

> Ok, now, `right click` on anywhere on the page and click on "Inspect" from the menu

![Chrome Inspecter](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2upprjvutruy4dxotl5t.png)

### Step 7

> This will open up a whole new section on the right side or the bottom of the page.

![Chrome DevTools Opens](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0wyq5vz68ra8i5ldkd6e.png)

### Step 8

> Inside the sidebar, click on "Console" from the top menu

![Console in Chrome DevTools](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ovnqj0gq0b9slrrxhjt.png)

### Step 9

> Now, copy over this piece of code and paste it right after the `>` sign

```js
(function run() {
    const coupons = Array.from(document.querySelectorAll('send-to-card-action'))
        .map(e => e.querySelector('.coupon-container .coupon-action.sc-send-to-card-action'))
        .filter(Boolean);

    const totalCoupons = coupons.length;
    console.log(`🛍️ Total coupons to add: ${totalCoupons}`);

    coupons.forEach((e, index) => {
        setTimeout(() => {
            e.click();
            const couponsLeft = totalCoupons - index - 1;
            console.log(`✨ Coupon added... ${couponsLeft} more left! ✨`);
            if (couponsLeft === 0) {
                console.log("🎉 All coupons have been added to your card. Enjoy your savings! 🎉");
            }
        }, index * 350);
    });

    if (totalCoupons === 0) {
        console.log("🎉 All coupons have been added to your card. Enjoy your savings! 🎉");
    }
})();
```

### Step 10

> Then, press `ENTER` and watch some magic happen in the background. Notice all the coupons being automatically clicked and added for you.
![Coupons Script](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lr877g8c0rikjw9pss9y.png)

### Step 11

> You should see a "Coupons left" counter on the sidebar, it tracks the number of coupons still to be added. Wait until that counter goes all the way down to 0.

![Coupons Left Counter](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nybzeawua21ppd3ul6pq.png)

### Step 12

> That's it, now all the coupons should be added to your account.

---

Now, I understand that this is clearly not a fully automated system, but it should at least help you avoid having to click on more than 100+ coupons on a regular basis. Let me know if you found this helpful at all. I am planning to build on top of this automation to not have to manually follow all these 12 steps, so hopefully, then, it would be even simpler.