Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Selenium: 'unexpected keyword argument 'executable_path'

I just started using selenium with Python and I keep getting the following error code:

TypeError: WebDriver.__init__() got an unexpected keyword argument 'executable_path'

Here's the code for the context:

from selenium.webdriver import Firefox
from selenium.webdriver.common.keys import Keys

url = 'https://example'
driver_path = r"D:\path\to\geckodriver.exe"

browser = Firefox(executable_path=driver_path)
browser.get(url)

Thanks in advance!

I checked the path, the version of the selenium package and made sure that I have the right geckodriver.exe but still get the error.

like image 559
Leo Avatar asked May 22 '26 07:05

Leo


1 Answers

As mentioned in my earlier solution, https://stackoverflow.com/a/76550727/7058266, this is due to changes in selenium 4.10.0: https://github.com/SeleniumHQ/selenium/commit/9f5801c82fb3be3d5850707c46c3f8176e3ccd8e

Changes_in_selenium_4_10_0

Note that executable_path was removed.

If you want to pass in an executable_path, you'll have to use the service arg now.

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()

But you no longer need to specify an executable_path due to a fully operational Selenium Manager in 4.10.0, so this is all you need:

from selenium import webdriver
from selenium.webdriver.firefox.service import Service

service = Service()
options = webdriver.FirefoxOptions()
driver = webdriver.Firefox(service=service, options=options)
# ...
driver.quit()
like image 52
Michael Mintz Avatar answered May 24 '26 20:05

Michael Mintz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!