2

I am trying to use the following simple piece of code to open a new session of Chrome with an extension on:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_extension(r'C:\\Users\\username\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Extensions\\iggpfpnahkgpnindfkdncknoldgnccdg\\5.17.1_0.crx')

driver = webdriver.Chrome(options=chrome_options)
driver.get("http://stackoverflow.com")

I get the error:

raise IOError("Path to the extension doesn't exist") OSError: Path to the extension doesn't exist

I believe I don't understand how to link to the path of an extension. Where is the .crx file? Do I have to zip the directory?

q0mlm
  • 313
  • 1
  • 3
  • 10
  • Well, have you tried running it as `root`? – Unsigned_Arduino Jun 14 '20 at 16:58
  • Thanks @Unsigned_Arduino, I have tried and still get the same error... – q0mlm Jun 14 '20 at 18:10
  • @DebanjanB this is a different error from the ones you have linked, do I have to open another question now or can you re-open this one? Thanks. – q0mlm Jun 14 '20 at 18:12
  • @mlm0b11011 Can you please explain how your question is different from the dup marked questions? Did you notice you have to pass the `extension.crx` file through `add_extension()` – undetected Selenium Jun 14 '20 at 18:14
  • @DebanjanB When I try to pass it as .crx I get the error "OSError: Path to the extension doesn't exist", I am linking to the path of the directory that contains the files of the extention. When I don't use the .crx at the end of the path the code finds the directory but tells me that permission is denied. – q0mlm Jun 14 '20 at 18:41
  • @mlm0b11011 Makes sense. So your basic hurdle is `OSError: Path to the extension doesn't exist` and not the one you have asked. – undetected Selenium Jun 14 '20 at 18:44
  • @DebanjanB maybe deceived by the formatting of [this answer] (https://stackoverflow.com/questions/16511384/using-extensions-with-selenium-python) I thought there were two ways of using `add_extension()` one without and one with .crx in the path. In the first case I get the error described in this question, in the second case the `OSError`. I can revise this question if you confirm that the only "right" error is the second one. – q0mlm Jun 14 '20 at 18:57
  • @DebanjanB I have edited the question accordingly to your comments – q0mlm Jun 15 '20 at 01:17
  • Solved it. I had to download the .crx file manually from the chrome webstore. – q0mlm Jun 15 '20 at 01:44

0 Answers0