Selenium Chrome Options and Capabilities Selenium Chrome Options and Capabilities selenium selenium

Selenium Chrome Options and Capabilities


There has been an issue: https://github.com/SeleniumHQ/selenium/issues/5722

It's easy. Call this enabler function after your switch window for your driver:

 def enable_download_in_headless_chrome(driver, download_dir):    # add missing support for chrome "send_command"  to selenium webdriver    driver.command_executor._commands["send_command"] = ("POST",'/session/$sessionId/chromium/send_command')    params = {'cmd': 'Page.setDownloadBehavior', 'params': {'behavior': 'allow', 'downloadPath': download_dir}}    command_result = driver.execute("send_command", params)expected_download = 'ur/download/path'opt = Options()opt.add_experimental_option("prefs", { \    'download.default_directory': expected_download,     'download.prompt_for_download': False,     'download.directory_upgrade': True,  })opt.add_argument('--headless')opt.add_argument('--window-size=1920,1080');login_page = "https://www.google.com"driver = webdriver.Chrome(options=opt)driver.implicitly_wait(5)driver.get(login_page)driver.maximize_window()#On below click you will be in new tabscoresheet_tab = driver.find_element_by_xpath("//*[@class='sideNav-item is--scoresheet']").click()instances = driver.window_handlesdriver.switch_to.window(instances[1]) # this is the new browser#this below function below does all the trickenable_download_in_headless_chrome(driver, expected_download)