Reputation: 541
My code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
option = webdriver.ChromeOptions()
driver = webdriver.Chrome(executable_path='./chromedriver.exe', options=option)
driver.get('https://www.google.com/')
Output:
WebDriver.__init__() got an unexpected keyword argument 'executable_path'
I'm trying to create a script to log in to a website. When I try to run this script, it gives me this error:
WebDriver.__init__() got an unexpected keyword argument 'executable_path'
Upvotes: 54
Views: 194050
Reputation: 221
Try this:
from selenium.webdriver.firefox.service import Service as FirefoxService
firefox_profile = webdriver.FirefoxProfile()
firefox_profile.set_preference("browser.download.folderList", 2)
firefox_profile.set_preference("browser.download.manager.showWhenStarting", False)
# firefox_profile.set_preference("browser.download.dir", str(output_directory))
firefox_profile.set_preference(
"browser.helperApps.neverAsk.saveToDisk", "application/zip")
service = FirefoxService(firefox_profile = firefox_profile)
browser = webdriver.Firefox(
service= service,
options = firefox_options
)
Upvotes: 0
Reputation: 15556
This is due to changes in selenium
4.10.0
:
https://github.com/SeleniumHQ/selenium/commit/9f5801c82fb3be3d5850707c46c3f8176e3ccd8e
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.chrome.service import Service
service = Service(executable_path='./chromedriver.exe')
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(service=service, options=options)
# ...
driver.quit()
Upvotes: 84
Reputation: 21
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=options)
Upvotes: 2
Reputation: 11
The latest Selenium doesn’t require a webdriver. You can remove executable_url from the argument, because you have installed the latest version of Selenium.
Upvotes: 1
Reputation: 41
I helped solve this in this GitHub post: self.driver = driver_klass(**driver_kwargs) TypeError: WebDriver.init() got an unexpected keyword argument 'executable_path' #128. Please note I'm using Scrapy to create web scrapers and Selenium to interact with the website.
SELENIUM_DRIVER_NAME = 'chrome'
SELENIUM_DRIVER_EXECUTABLE_PATH = None #not actually necessary, will work even if you comment this line out
SELENIUM_DRIVER_ARGUMENTS=[] #put '--headless' in the brackets to prevent browser popup
scrapy runspider <scraper_name>.py
in your terminal and enjoy!Quick explanation of what's happening:
Upvotes: 2
Reputation: 271
Note: Remove executable_url
from the argument, because you have installed the latest version of Selenium if you have Selenium above the 4.6.0, you don't need to add executable_url
, and in the latest version of Selenium, you don't need to download webdriver.
Just copy the below code and run the your Python file simple.
from selenium import webdriver
driver=webdriver.Chrome()
driver.get("https://www.facebook.com/")
Upvotes: 27
Reputation: 8508
Just remove executable_path
(see below), if you do not wish to set the driver.exe
path manually. With the latest Selenium (v4.6.0 and onwards), its in-built tool, known as SeleniumManger
, can download and handle the driver.exe
if you do not specify.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
option = webdriver.ChromeOptions()
driver = webdriver.Chrome(options = option)
driver.get('https://www.google.com/')
Upvotes: 6