Reloading a Chrome Extension using Selenium WebDriver
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.
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:
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).
Click it to see a “Reloaded” toast. Now, if we return to ModHeader again, it will have loaded properly.
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:
- Navigate to the Extension…