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?
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])