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

626 Views Asked by At
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"
driver = webdriver.Chrome(chrome_options=options, executable_path="C:/Utility/BrowserDrivers/chromedriver.exe", )
driver.get('http://google.com/')

Above is my code, but when I try to run it I am getting the chrome_options error. Could anyone please help me in resolving this?

1

There are 1 best solutions below

0
sashkins On

webdriver.Chrome constructor doesn't have the 'chrome_options' parameter anymore. It has been deprecated, and now you have to use the 'options' parameter.

Also, the executable_path has been deprecated. Check this post

Here's Chrome class in Selenium4:

class WebDriver(ChromiumDriver):
"""Controls the ChromeDriver and allows you to drive the browser."""

def __init__(
    self,
    options: Options = None,
    service: Service = None,
    keep_alive: bool = True,
) -> None:
    """Creates a new instance of the chrome driver. Starts the service and
    then creates new instance of chrome driver.

    :Args:
     - options - this takes an instance of ChromeOptions
     - service - Service object for handling the browser driver if you need to pass extra details
     - keep_alive - Whether to configure ChromeRemoteConnection to use HTTP keep-alive.
    """
    self.service = service if service else Service()
    self.options = options if options else Options()
    self.keep_alive = keep_alive

    self.service.path = DriverFinder.get_path(self.service, self.options)

    super().__init__(
        DesiredCapabilities.CHROME["browserName"],
        "goog",
        self.options,
        self.service,
        self.keep_alive,
    )