while many answers here are correct, they cannot easily be automated.
Here's what I did:
a) Anand Gautams solution does work under certain circumstances: f.e. local and manual use of tests. I use webdriver-manager in those cases and it works well. If Anand had posted an Answer instead of a comment, i would mark that as a Solution as it partially is.
However:
b) In stage and production and when automated on a company server having a program download things is generally a bad idea. Yes you can whitelist the source but for a multitude of security reasons (from technical to legal) you shouldn't.
My solution for this was a rather daunting one: I made a collection of all reasonable webdriver versions for all the supported browsers (which is being expanded regularly since clients have a completely different definition of "reasonable") and made a module that checks for installed browsers and their versions and pairs them with the corresponding webdriver version (for local usage) or enables you to manually choose a version to test with (for test automation on a server).
b1) I'm not sure if I'm allowed to post the module here publicly, i will ask and edit the answer should this be the case.
b2) While this solution enables you to automate support for a great bandwidth of browsers and versions within a closed system it is very tedious and maintaining it can be work intensive at times. I would definitely try to avoid this solution if possible.
For now I will mark this answer as a solution. I hope somebody comes up with something better in the future.
'pip install webdriver-manager
import:from webdriver_manager.chrome import ChromeDriverManager
. Then instead of your local chromedriver path, use this:driver = webdriver.Chrome(ChromeDriverManager().install())
this should work. Basically, it takes care of version compatibilities between driver and browser versions – Triturate