I made a simple Selenium script below in Python. This script runs perfectly for me, even though I don't specify the location of ChromeDriver (and as far as I can tell, I don't even have ChromeDriver installed). All other examples I've seen of simple Selenium programs require the user to specify the location of ChromeDriver.
Why does it not require ChromeDriver here?
from selenium import webdriver
website_url = 'https://microsoft.com'
driver = webdriver.Chrome()
driver.get(website_url)
driver.quit()
As of selenium
4.10.0
the driver manager is fully integrated, and will silently download drivers as needed. (Eg. On Mac/Linux, drivers are automatically downloaded to the ~/.cache/selenium
folder if not found on the PATH.) Slightly earlier versions of selenium
had a beta of the driver manager.
Optionally now, if you want to specify a PATH, you can do so via the service
arg:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
service = Service(executable_path="PATH_TO_DRIVER")
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(service=service, options=options)
# ...
driver.quit()
But specifying the executable_path
is optional now (and must be done via the service
arg).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With