3

UPDATED QUESTION:

At this point, if anyone can give me any tips on how I can add any type of extension inside selenium during run time, my goal was to be able to run the script and have chrome have the extension installed and active to go, since when you run the chromedriver, chrome is as if vanilla (there are no extensions installed, or active) I've tried the following answers and have had no luck, I've tried finding videos, looking into the documents, but I just keep failing, If anyone has any insight, I would really appreciate it!!!

Original post below

I'm trying to unblock origin extension to work on my chrome when using selenium and the above code seems to fail, I've tried a few methods on getting this to work, but all have failed, all attempts on getting this to work are based on what I've read here or on youtube! If someone could help me out here that would be great!

Imports for entire code, I'm extremely new to selenium so I placed all the imports that I'm still playing around with the libraries to figure out what does what.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException

First Attempt:

option = webdriver.ChromeOptions()
option.add_argument('load-extension=' + 'uBlock-Origin_v1.16.18.crx')

Second Attempt:

path_to_extension("C:\Selenium\uBlock-Origin_v1.16.18.crx")

option = webdriver.ChromeOptions()
option.add_argument('load-extension=' + path_to_extension)

Third Attempt:

#adding ublock Origin
path_to_extension = (r'C:\Selenium\1.16.18_0')

# example option: add 'incognito' command line arg to options
option = webdriver.ChromeOptions()
option.add_argument("--incognito")
options.add_argument('load-extension=' + path_to_extension)

The first two attempts code, was based on the idea that I had to install the extensions .crx file, individually and place the directory for that file in order to have the extension work using the method below: First attempt(without specifying the directory)

Second attempt (specifying with "path_to_directory" variable) I installed .crx separately using a site called "https://chrome-extension-downloader.com/", and placed it in a directory in this case my C:\Selenium\ folder.

The Third attempt, Consisted of me locating the directory of where my extension (ublock) was installed for my regular chrome browser, and copying the folder (in this case "1.16.18_0" folder and placing it inside ("C:\Selenium) directory for easy access, I read to place an r before quoting the path, hense the code.

path_to_extension = (r'C:\Selenium\1.16.18_0')

Any suggestions would help, I don't mind completely scraping what I have in order to get this to work, I simply tried all the methods that I've seen on the internet thus far.

I also recently attempted to use the following method which failed

option.add_extension(r'C:\Selenium\uBlock-Origin_v1.16.18.crx')
david yeritsyan
  • 422
  • 6
  • 26

1 Answers1

7

Turns out that the only reason I wasn't able to have Ublock enabled was simply because I had incognito enabled which for some reason was causing the extension not to load, but once I commented it out the extension started working beautify. I hope this helps anyone else who might be in the same situation.

#Adding adblocker
option = webdriver.ChromeOptions()
#option.add_argument("--incognito")
option.add_extension(r"C:\Users\David\Documents\Extensions\uBlock-Origin_v1.16.18.crx")
david yeritsyan
  • 422
  • 6
  • 26