To pass in an executable_path
, you can use the service
arg.
Here's an example for Chrome:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
service = Service(executable_path="./chromedriver")
options = webdriver.ChromeOptions()
options.add_argument('--headless')
driver = webdriver.Chrome(service=service, options=options)
# ...
driver.quit()
Here's an example for Firefox:
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
service = Service(executable_path="PATH_TO_GECKODRIVER")
options = webdriver.FirefoxOptions()
driver = webdriver.Firefox(service=service, options=options)
# ...
driver.quit()
You no longer need to specify an executable_path
due to a fully operational Selenium Manager in 4.11.2
, so this is all you need:
from selenium import webdriver
driver = webdriver.Chrome()
# ...
driver.quit()
Here's one with the placeholders for options / preferences:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
service = Service()
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(service=service, options=options)
# ...
driver.quit()