DEV Community

Tony Colston
Tony Colston

Posted on • Updated on

Headless Selenium testing with Chrome extensions is broke AF

In case you ever wondered, you cannot test extensions with Selenium and headless Chrome. Chrome does not support this type of testing.

options = webdriver.ChromeOptions()
# print(dir(options))

# see this https://stackoverflow.com/questions/45372066/is-it-possible-to-run-google-chrome-in-headless-mode-with-extensions
# you cannot test extensions if you are in headless mode?
# it is a bug
options.add_argument('headless')

But the good news you can load an extension with Selenium easy-peasy. As long as you are not headless.

options.add_argument("--load-extension={0}".format("e:/projects/headless/myext"))

Another thing I found at least in Windows 10 with this version of chromedriver

ChromeDriver 75.0.3770.140 (2d9f97485c7b07dc18a74666574f19176731995c-refs/branch-heads/3770@{#1155})

I would get a errant chromedriver.exe process that hung around after each test (I was using the Python bindings).

To fix that I switched to using webdriver.Remote and ran the chromedriver.exe by hand only one time.

Top comments (0)