[Fix] KeyError ‘google-chrome’

The error “KeyError: ‘google-chrome'” is an error that is invoked whenever you are using ChromeDriverManager().install() with selenium in python . Given below is the snippet of the error, which you can find here:

KeyError: 'google-chrome'

I would like to share with you the steps I took to fix the “KeyError: ‘google-chrome'” in your python file.

Why “KeyError ‘google-chrome'” error is seen?

The error, “KeyError: ‘google-chrome'” is seen because you are not using proper dependencies in your selenium 3 or selenium 4. The error is also likely to show if webdriver-manger is not updated to the latest version or if you selenium is not updated to the latest version.

The detailed solution to fix the error “KeyError: ‘google-chrome'”, is given below:

How to fix the error, “KeyError ‘google-chrome'”?

To fix the error, you can try to install webdriver-manager and also update your selenium version in your project file is not up to date with the latest version.

To fix the error, “KeyError: ‘google-chrome'”, follow one of the methods given below:

Method 1: Install webdriver-manager and selenium

To fix the error, “KeyError: ‘google-chrome'”, you will have to update or install the latest version of webdriver-manager and also the latest version of selenium.

To Install the latest version of  webdriver-manager and selenium you will have to run the below mentioned command:

pip install webdriver-manager

Then you will have to install the latest version of selenium. You can install the latest version by running the below mentioned command.

pip install selenium

This should fix your error, “KeyError: ‘google-chrome'”.

Method 2: Update your code.

To fix the error, “KeyError: ‘google-chrome'”, you will have to update your code by following steps given below:

In case you are using Selenium 3, you will have to update your imports and dependencies. You will have to use the following code given below:

# selenium 3
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())

In case you are using Selenium 4, you will have to update your imports and dependencies. You will have to use the following code given below:

# selenium 4
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))

This should fix your error, “KeyError: ‘google-chrome'”.

Conclusion

To fix the error “KeyError: ‘google-chrome'”, you will have to update or install the latest version of webdriver-manager and also the latest version of selenium. You will also have to call proper dependencies depending on your selenium version