Search code examples
selenium-webdriverselenium-chromedriver

Cannot override "download.prompt_for_download" value if running on incognito mode


From Chromedriver 116 and higher, if you need to download a file on incognito mode, the variable "download.prompt_for_download = False" on the chromeOptions is not not taken into account.

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--incognito")
prefs = {
        "download.prompt_for_download": False,
    }
chrome_options.add_experimental_option("prefs", prefs)

if we remove --incognito args from chrome options, it works fine. Any suggestions on this?


Solution

  • Adding the experimental localState.browser.enabled_labs_experiments=["download-bubble@2", "download-bubble-v2@2"] as shown below worked even for incognito mode

        driver = chrome
        autodownload=true
        timeouts {
            implicitlywait=90000
            fluentwait=90000
        }
        capabilities {
            browserName = "chrome"
            acceptInsecureCerts = true
            acceptSslCerts = true
            handlesAlerts = true
            validateTLSCertificates=false
            "goog:chromeOptions" {
                args = ["start-maximized", "remote-allow-origins=*", "test-type", "no-sandbox", "ignore-certificate-errors", "--window-size=1920,1080"
                    "incognito", "disable-infobars", "disable-gpu", "disable-default-apps", "disable-popup-blocking", "disable-extensions-file-access-check",
                    "ignore-ssl-errors=yes", "disable-extensions"],
                prefs {
                    download.prompt_for_download=false
                    safebrowsing.enabled=false
                    profile.default_content_settings.popups=0
                    #download.default_directory=${user.dir}"\\src\\test\\resources\\downloads"
                }
                localState {
                    browser.enabled_labs_experiments=["download-bubble@2", "download-bubble-v2@2"]
                }
            }
        }
    }```