Solve – DeprecationWarning: executable_path has been deprecated selenium python

DeprecationWarning: executable_path has been deprecated selenium python is a popular Python error that occurs when the key executable_path is going to be deprecated.

In this article I am going to explain why this error is showing up in the first place, I will try to explain to you how I solved it and how other developers managed to solve this issue.

Describing DeprecationWarning: executable_path has been deprecated selenium python

No matter the code you are running with Python and Selenium the occurrence of this error is very possible when the right conditions are present.

Here is an example of how the error or warning looks like

                                                                       #
Demo.py:7: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
driver = webdriver.Chrome(ChromeDriverManager().install())
                                                                       #

The error means that in the upcoming releases of selenium the key executable_path will be deprecated.

Solution 1 : upgrade to Selenium 4 and install Webdriver Manager

Follow the steps bellow in order to get ride of this warning aka error.

Let us upgrade to Selenium 4 by running a simple pip3 install

                                                                       #
pip3 install -U selenium
                                                                       #

Second step is to install Webdriver Manager for Python with a simple pip3 install.

                                                                       #
pip3 install webdriver-manager
                                                                       #

Now that we have Selenium 4 the error should be gone, you can as a result execute this code with no problem.

                                                                       #
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.get("https://www.google.com")
                                                                       #

I hope this helped remove the error for you, please consider donating to our Kofi account in order to support the website, keep in mind that you do not have to do this, it is just a donation button, the content on our website will always be free.

Solution 2 : install webdriver manager with Firefox

This solution is for Firefox users only, if you are a chrome user the first solution should work for you, not this one.

First run the following line of code in order to install the webdriver manager.

                                                                       #
pip install webdriver-manager
                                                                       #

The code is going to be different than the one above since we are now using Firefox.

                                                                       #
from selenium.webdriver.firefox.service import Service
from webdriver_manager.firefox import GeckoDriverManager
driver = webdriver.Firefox(service=Service(executable_path=GeckoDriverManager().install()))
                                                                       #

The error should be gone by now, I hope this helped you.

Solution 3 : use ChromeOption and pass the ChromeOptions object into the ChromeDriver constructor

The last solution is to create an instance of ChromeOption.

Then passing the ChromeOptions object into the ChromeDriver constructor.

                                                                       #
ChromeOptions options = new ChromeOptions();

options.addExtensions(new File("/path/to/extension.crx"));

ChromeDriver driver = new ChromeDriver(options);
                                                                       #

You can now specify WebDriver capabilities that are not specific to ChromeDriver.

For example

                                                                       #
// Add a ChromeDriver-specific capability.

options.addExtensions(new File("/path/to/extension.crx"));

ChromeDriver driver = new ChromeDriver(options);
                                                                       #

Summing-up

Thank you guys for reading, I hope this article helped you solve the issue at hand, I hope the error is gone after following one of the solutions I described above. Keep coding, errors are normal, keep learning, cheers.

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