2

I've recently have gotten a problem where, while using Selenium, wanted to use my default chrome browser profile, so it's signed in and everything, but when searched up on google, it gave me a code which is basicallty this:

chrome_options = Options()
chrome_options.add_argument("[path to the profile]")
driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=[path to the webdriver])

The error that I've been getting is:

NameError: name 'Options' is not defined

How can I fix this and maybe there's a better way to load a chrome profile?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
martispyc
  • 77
  • 1
  • 3
  • 8

2 Answers2

3

There are two things. Possibly you haven't imported the required module for Options. So to use an instance of Options you have to include the following import:

from selenium.webdriver.chrome.options import Options

Moreover, chrome_options is deprecated and you have to use options instead. So your effective code block will be:

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

chrome_options = Options()
chrome_options.add_argument("[path to the profile]")
driver = webdriver.Chrome(options=chrome_options, executable_path=[path to the webdriver])
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    Ok, it worked, but my profile isn't loading, without errors and correct .add_argument, any common reasons why? – martispyc Jan 29 '21 at 22:08
  • @martispy For loading [**Chrome Profile**](https://stackoverflow.com/questions/50635087/how-to-open-a-chrome-profile-through-user-data-dir-argument-of-selenium/50637211#50637211) check [this](https://stackoverflow.com/questions/49270109/how-to-open-a-chrome-profile-through-python/49280195#49280195) and [this](https://stackoverflow.com/questions/56443546/how-to-use-existing-login-token-for-telegram-web-using-selenium-webdriver/56445102#56445102) discussion. – undetected Selenium Jan 29 '21 at 22:12
2

You need to import Options into the namespace:

from selenium.webdriver.chrome.options import Options

chrome_options = Options()
C.Nivs
  • 12,353
  • 2
  • 19
  • 44
  • 1
    Ok, it worked, but my profile isn't loading, without errors and correct .add_argument, any common reasons why? – martispyc Jan 29 '21 at 22:03