I am trying to load a google chrome extension
with Selenium WebDriver
.
But I receive an error OSError: Path to the extension doesn't exist
.
Here is the code I am using:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
from os import path
path = "path to chrome driver"
chrome_options = webdriver.ChromeOptions()
chrome_options.add_extension('Adblock-Plus_v1.12.4_0.crx') # ALTERNATIVE 0
driver = webdriver.Chrome(path, chrome_options=chrome_options)
After reading various similar questions on this site I tried the following two alternatives:
# Alternative 1
chrome_options.add_extension('~/Library/Application\ Support/Google/Chrome/Default/Extensions/[Extension ID]/Adblock-Plus_v1.12.4_0.crx')
#Alternative 2
chrome_options.add_extension(path.abspath("Adblock-Plus_v1.12.4_0.crx"))
But none of them work. Alternative 1 gives same error message as the original code whereas Alternative 2 gives error AttributeError: 'str' object has no attribute 'abspath'
Does anyone have a clue what I could be doing differently?