We can automate the task of downloading the binary and configuring the path.
We dont have to worry about the browser version or the binary version
This can be done by using [webdriver-manager][1]
pip install webdriver-manager
Now the above code in the question will work simply with the below change,
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
The same can be used to set Firefox, Edge, and ie binaries.
[1]: https://pypi.org/project/webdriver-manager/
Original Answer - https://stackoverflow.com/a/58727916/9928905
I see the discussions still talk about the old way of setting up chromedriver by downloading the binary and configuring the path manually.
This can be done automatically using [webdriver-manager][1]
pip install webdriver-manager
Now the above code in the question will work simply with below change,
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
The same can be used to set Firefox, Edge and ie binaries.
[1]: https://pypi.org/project/webdriver-manager/