Reloading a Chrome Extension using Selenium WebDriver

Handling multi-level shadow roots in Selenium WebDriver

Zhimin Zhan
4 min readJan 31, 2022

--

A repost of my daughter’s article with permission. I added it here for the convenience of my blog subscribers. Reloading a Chrome extension involves multi-level shadow roots. This article shows how.

This article is included in my “How to in Selenium WebDriver” series.

Some automated tests require browser extensions to complete an action. For instance, testing whether a login ‘Remember Me’ works via a cookie.

However, not all browser extensions work immediately, some may need to be refreshed first.

This tutorial will show you a script that will refresh a Chrome extension before a test begins.

The Scenario

We want to log in to a sample site with a cookie. To store this cookie, I will use the Chrome ModHeader extension in this tutorial. First, start Chrome with the extension (I used this tutorial for how to drive Chrome with Extensions using Selenium WebDriver).

Following this, just running the basic test will give you this window:

ModHeader extension’s link displays “Your file couldn’t be accessed”.

It knows we are trying to open ModHeader (in the top bar), but cannot access it.

If we manually go to the Extension Manager (chrome://extensions), there is a reload option for each extension (highlighted in red below).

Chrome Extension Manager, with the reload icon highlighted in red

Click it to see a “Reloaded” toast. Now, if we return to ModHeader again, it will have loaded properly.

ModHeader extension page loaded correctly.

These are the basic steps we want our script to replicate.

In summary, to load an extension properly, we want to write a script that will:

  1. Navigate to the Extension

--

--

Zhimin Zhan

Test automation & CT coach, author, speaker and award-winning software developer. Help teams succeed with Agile/DevOps by implementing real Continuous Testing.