This question has been asked many times before in similar disguises and the answers have usually advised to match versions. However, i have often struggled to match versions (for various reasons) and this is rather cumbersome when the versions keep changing.
For this reason, I use the ChromeDriverManager()
which installs the correct version at each time.
You need to install webdriver-manager:
pip install webdriver-manager
And this is the working code
# selenium 4
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
service=Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=service)
You can find the docs here:
https://pypi.org/project/webdriver-manager/
This module recognises and has solved a problem for us all:
It’s boring!!! Moreover every time the new version of driver released, you should go and repeat all steps again and again.
I hope it helps.