my script was working fine until I tried using the undetected chrome browser. When I installed it, I encountered the following error: "WebDriver.init() got an unexpected keyword argument 'chrome_options'". I uninstalled it and attempted to use my normal chrome driver again, but I still got the same error. I have been searching for a solution for over four hours, but I haven't been able to fix it. Here's an example of my script:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from time import sleep
WINDOW_SIZE = "2500,2200"
caps = DesiredCapabilities().CHROME
Chrome_options = webdriver.ChromeOptions()
Chrome_options.add_argument("--incognito")
Chrome_options.add_argument("--log-level=3")
Chrome_options.add_argument("window-position=-5000,100")
caps["pageLoadStrategy"] = "eager"
Chrome_options.add_argument("--window-size=%s" % WINDOW_SIZE)
Chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Chrome(chrome_options=Chrome_options,executable_path='./chromedriver')
wait = WebDriverWait(driver, 10)
driver.get('www.google.com')
sleep(100)
TypeError: WebDriver.init() got an unexpected keyword argument 'chrome_options'
I tried to use undetected chrome browser and it miss up all my scripts using normal chrome driver
Maybe you upgrade the selenium, you should use codes like this:
view the document or source codes from github https://github.com/SeleniumHQ/selenium/blob/trunk/py/selenium/webdriver/chrome/webdriver.py#L26-L36 https://www.selenium.dev/documentation/webdriver/drivers/
from selenium.webdriver.edge.service import Service
from selenium.webdriver import ChromeOptions
chrome_options = ChromeOptions()
service=Service(executable_path=driverpath)
driver = webdriver.Edge(options=chrome_options, service = service)
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: