0

Exception: selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: cannot parse capability: goog:chromeOptions from invalid argument: unrecognized chrome option: prefs

Chrome options I'm using:

 import undetected_chromedriver.v2 as uc
 chrome_options = uc.ChromeOptions()
 chrome_options.add_argument("--window-size=800,800")
 chrome_options.add_argument("--no-sandbox")
 chrome_options.add_argument("--start-maximized")
 chrome_options.user_data_dir = project_settings.LOCAL_PROFILES_STORAGE_PATH + "\\" + phone number
 download_path = "D://driver"
 preferences = {"download.default_directory": download_path}
 chrome_options.add_experimental_option('prefs', preferences)
 chrome_options.to_capabilities()
 chrome_options.add_argument('--no-first-run --no-service-autorun --password-store=basic')
 chrome_options.add_argument('--disable-dev-shm-usage')
 chrome_options.add_argument('--profile-directory=Default')
 return uc.Chrome(options=chrome_options)
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

1 Answers1

0

On Linux, you can use download.default_directory to specify a download folder for undetected_chromedriver. For example,

import undetected_chromedriver.v2 as uc    
options.add_argument("--download.default_directory --your_download_folder_path")
driver = uc.Chrome(options=options)

If the method above doesn't work or you're on a Windows machine, you can try the following method:

options = uc.ChromeOptions()
driver = uc.Chrome(options=options)
driver.command_executor._commands["send_command"] = ("POST", '/session/$sessionId/chromium/send_command')
params = {'cmd': 'Page.setDownloadBehavior',
          'params': {'behavior': 'allow', 'downloadPath': your_download_folder_path}}
driver.execute("send_command", params)
Ryan
  • 11
  • 3