DEV Community


Automate email settings with JavaScript

Daniel Deutsch
Connecting Law and Programming.
・3 min read

Automate email settings with JavaScript

unsplash Photo by Samuele Errico Piccarini

In my previous article I described how to use JavaScript in the browser console to get tedious tasks on the web much faster done. Of course this approach is limited. A way to go much further and beyond is to use a automation framework like Selenium. In this article I show how flexible and fast you can program a script that helps you save a lot of time.

➡️ Github Repo is available here ⬅️

📄 Table of contents

"The first rule of any technology used in a business is that automation applied to an efficient operation will magnify the efficiency. The second is that automation applied to an inefficient operation will magnify the inefficiency." - Bill Gates

The problem

The page requires me to check on/off each checkbox for an email notification of each group.


I don't waste my time clicking through all my groups. offers an option to disable all notifications, but I want to receive updates from some selected groups.
Another thing is that they have "Reminders", that require even more clicking with a dropdown menu. This dropdown menu can't even be handled by the console code, that I have shown in the previous article.

Therefore I decided to write an automated script that does all that for me.


How to automate with Selenium webdriver

Selenium allows to use a webdriver to go through the browser and performs actions, that a human being could also do (like clicking on elements).

The process of automating is simple:

  • find the element with the inspector in your browser

  • get the element with driver.findElement

  • perform actions on that element with .then (promises in JS) or functions from the framework like .click()

  • after performing the tasks, be sure to driver.quit(); to end the driver

Using it on clicking SPAM checkboxes on


In this example I am using the Selenium webdriver.

The setup in Node.js is pretty easy:

var webdriver = require('selenium-webdriver'),
    By = webdriver.By,
    until = webdriver.until;

var driver = new webdriver.Builder().forBrowser('chrome').build();
Enter fullscreen mode Exit fullscreen mode

Going to the settings

To get to the notifications section I simply go to their login page, send my credentials to log in and click all the way to the settings.


var mail = driver.findElement('email'));
var pass = driver.findElement('password'));


            'valign--middle display--none atMedium_display--inline'
driver.findElement(webdriver.By.xpath('//a[text()="Email Updates"]')).click();
Enter fullscreen mode Exit fullscreen mode

Identify the elements and iterate over them

I identify all checkboxes and dropdowns and call a function (clickingAll) on each element.

const list = driver.findElements(

list.then(function(elements) {
    var links = => {
        return elem.getAttribute('href');
    promise.all(links).then(linkRefs => {
        linkRefs.forEach(element => {
Enter fullscreen mode Exit fullscreen mode

The clickingAll() function actually clicks the elements and tests if the boxes are already unchecked (since we don't want to simply click everything, but rather uncheck all boxes).

var clickingAll = () => {
            webdriver.By.xpath('//i[@class="icon-s icon-checkbox pseudocheckbox "]')
        .then(elements => {
   => {
                elem.getAttribute('aria-checked').then(check => {
                    if (check === 'true') {

    try {
            .then(null, err => {
                if (err) {
                    return false;
    } catch (e) {
        return false;
Enter fullscreen mode Exit fullscreen mode

See the result on Youtube


If you gained something from this article let me know with a comment or heart. Make sure to follow for more :)

Discussion (0)