It seems that this parameter ('executable_path') might not be accepted by the webdriver.Firefox() constructor, which is causing the error. How should I specify the executable path to correctly initialize the Firefox WebDriver in my code?
I'm getting a 'TypeError' with the following message:
TypeError: WebDriver.init() got an unexpected keyword argument 'executable_path'
This is my code snippet:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.service import Service
#from selenium.webdriver.firefox.options import Options as Firefox_Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
import pandas as pd
# Opciones de navegación
options = Options()
options.add_argument('--start-maximized')
options.add_argument('--disable-extensions')
driver = webdriver.Firefox()
driver_path = 'C:\\x\\x\\x\\x\\geckodriver-v0.33.0-win32\\geckodriver.exe'
#Inicializar driver
driver = webdriver.Firefox(executable_path =r'C:\\x\\x\\x\\x\\geckodriver-v0.33.0-win32\\geckodriver.exe')
#create a new Firefox web driver instance
#driver = webdriver.Firefox(service=service)
#Iniciar en pantalla 2
driver.set_window_position(2000, 0)
driver.maximize_window()
time.sleep(1)
#Inicializamos el navegador
driver.get('https://eltiempo.es')
WebDriverWait(driver, 5)\
.until(EC.element_to_be_clickable((By.CSS_SELECTOR,
'button.didomi-components-button didomi-button didomi-dismiss-button didomi-components-button--color didomi-button-highlight highlight-button'.replace(' ', '.'))))\
.click()
WebDriverWait(driver, 5)\
.until(EC.element_to_be_clickable((By.CSS_SELECTOR,
'input#inputSearch')))\
.send_keys('Madrid')
WebDriverWait(driver, 5)\
.until(EC.element_to_be_clickable((By.CSS_SELECTOR,
'i.icon.icon-search')))\
.click()
WebDriverWait(driver, 5)\
.until(EC.element_to_be_clickable((By.CSS_SELECTOR,
'i.icon_weather_s.icon.icon-local')))\
.click()
WebDriverWait(driver, 5)\
.until(EC.element_to_be_clickable((By.XPATH,
'/html/body/div[7]/main/div[4]/div/section[4]/section/div/article/section/ul/li[2]/a')))\
.click()
WebDriverWait(driver, 5)\
.until(EC.element_to_be_clickable((By.XPATH,
'/html/body/div[7]/main/div[4]/div/section[4]/section/div[1]/ul')))
texto_columnas = driver.find_element_by_xpath('/html/body/div[7]/main/div[4]/div/section[4]/section/div[1]/ul')
texto_columnas = texto_columnas.text
tiempo_hoy = texto_columnas.split('MaƱana')[0].split('\n')[1:-1]
horas = list()
temp = list()
v_viento = list()
for i in range(0, len(tiempo_hoy), 4):
horas.append(tiempo_hoy[i])
temp.append(tiempo_hoy[i+1])
v_viento.append(tiempo_hoy[i+2])
df = pd.DataFrame({'Horas': horas, 'Temperatura': temp, 'V_viento(km_h)':v_viento})
print(df)
df.to_csv('tiempo_hoy.csv', index=False)
driver.quit()
Additional information:
- Python version: Python 3.11
- GeckoDriver version: Selenium 0.33
- Eclipse IDE PyDev package Explorer,working in NewModule.py
I attempted to initialize the Firefox WebDriver in Selenium using the executable_path parameter, as shown in the following code snippet, and I've change the driver_path using the actual path of the webdriver but didn't work either:
driver_path = 'C:\\x\\x\\x\\x\\geckodriver-v0.33.0-win32\\geckodriver.exe'
driver = webdriver.Firefox(executable_path=driver_path)
I expected that this code would correctly initialize the Firefox WebDriver with the specified executable_path. My intention was to use this WebDriver instance for web automation tasks.
What actually resulted? Instead, I encountered a 'TypeError' with the following error message:
TypeError: WebDriver.init() got an unexpected keyword argument 'executable_path'
This error message suggests that the executable_path parameter may not be accepted by the webdriver.Firefox() constructor, which led to my confusion. My question is how to correctly specify the executable path for initializing the Firefox WebDriver.
If you want to pass in an
executable_path, use theservicearg. Here's the Firefox version: