WebDriver init() got unexpected arg 'executable_path' in Selenium Python

Issue:

I am attempting to create a script to log in to a website using the following 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/')

However, when I run the script, I receive the following error: WebDriver.__init__() got an unexpected keyword argument 'executable_path'

Answer:

The error message suggests that the webdriver.Chrome class does not recognize the executable_path argument.

To fix this issue, you need to modify the code as follows:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--headless')  # Optional: Run in headless mode (without GUI)

driver = webdriver.Chrome(options=options)

driver.get('https://www.google.com/')

Make sure you have the correct path to the chromedriver.exe file, and update it accordingly if needed.