Last active
November 3, 2020 15:23
-
-
Save cgoldberg/e6e2a1ef3535f8d614462cc42c935f33 to your computer and use it in GitHub Desktop.
Python - Selenium WebDriver - Installing an unpacked Chrome Extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
from selenium.webdriver.chrome.options import Options | |
unpacked_extension_path = '/path/to/unpacked/extension/' | |
options = Options() | |
options.add_argument('--load-extension={}'.format(unpacked_extension_path)) | |
driver = webdriver.Chrome(options=options) |
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import WebDriverException
chrome_options = webdriver.ChromeOptions()
driver = webdriver.Chrome(options=chrome_options,executable_path='/usr/lib/chromium-browser/chromedriver')
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
anyone see any issues? working with the same code here, it loads the extension though shuts down immediately.... I tried running the code with "driver.implicit_wait(5)" and/or "driver.add_experimental_option=("detach", True)" to keep the browser open to get "https://www.google.com/"; Lines of code seem to be unread past "driver = webdriver.Chrome(options=options, executable_path=r'C:/Webdriver/chromedriver.exe')".
https://gyazo.com/342f031ad308767ef27a3576c6b91256
SCRIPT
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
unpacked_extension_path = 'C:/Users/Win_10/AppData/Local/Google/Chrome/User Data/Default/Extensions/ohjocgmpmlfahafbipehkhbaacoemojp/1.1.4_0/'
options = Options()
options.add_argument('--load-extension={}'.format(unpacked_extension_path))
driver = webdriver.Chrome(options=options, executable_path=r'C:/Webdriver/chromedriver.exe')
driver.get('https://www.google.com/')
ERROR
Traceback (most recent call last):
File "C:/Users/Win_10/AppData/Local/Programs/Python/Python38-32/winker.py", line 8, in
driver = webdriver.Chrome(options=options, executable_path=r'C:/Webdriver/chromedriver.exe')
File "C:\Users\Win_10\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 76, in init
RemoteWebDriver.init(
File "C:\Users\Win_10\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in init
self.start_session(capabilities, browser_profile)
File "C:\Users\Win_10\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\Win_10\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Win_10\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created
from no such window: window was already closed
(Session info: chrome=83.0.4103.97)