Fixing Selenium ChromeDriver error – DeprecationWarning: use options instead of chrome_options

Selenium ChromeDriver error – DeprecationWarning: use options instead of chrome_options is an error which occurs when you use chrome_options which is now deprecated.

In this post/article I will get into what happens when you get this error and how to take care of it while also trying to present other possible solutions if any.

Explaining Selenium ChromeDriver error – DeprecationWarning: use options instead of chrome_options

This is an error that occurs when you use chrome_options which is now deprecated.

Your error message should match the one bellow. We want to avoid confusion by not mixing between error messages.

                                                                       #
DeprecationWarning: use options instead of chrome_options
driver.get(config("https://www.twitter.com"))
.....
raise UndefinedValueError('{} not found. Declare it as envvar 
or define a default value.'.format(option))
decouple.UndefinedValueError: ttps://www.twitter.com not found. 
Declare it as envvar or define a default value.
                                                                       #

Bellow I will present one solution which has worked for me and other developers.

Solution : use options instead of the deprecated chrome_options

This error occurs usually when you make two mistakes. First, you use chrome_options which is now deprecated. Second, you do not pass the path of the ChromeDriver to webdriver.

The fixes are simple first you need to use options instead of the now deprecated chrome_options. And you need to specify the path to the ChromeDriver and pass it to webdriver just like in the line bellow.

                                                                       #
driver = webdriver.Chrome(executable_path=r'C:\chromedriver_win32\chromedriver.exe', options=options)
                                                                       #

The lines of code where we use (options instead of chrome_options) bellow should precede the line above inside your script.

                                                                       #
options = webdriver.ChromeOptions() # using "options" instead of "chrome_options"
options.add_argument('--headless')
                                                                       #

I hope this solution helped you solve the issue. Thank you for reading.

Summing-up

I hope this article helped you solve the error, If not, I hope the solutions presented here guided you at least in the right direction. Keep coding and cheers, see you in another post.

If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/