Access to file download dialog in Firefox

前端 未结 11 2375
一个人的身影
一个人的身影 2020-11-22 07:02

Is there any kind of API that can allow me to manipulate a file download dialog in Firefox? (I want to access the one that appears when user does something, not initiate one

11条回答
  •  粉色の甜心
    2020-11-22 07:52

    I was facing the same issue. In our application the instance of FireFox was created by passing the DesiredCapabilities as follows

    driver = new FirefoxDriver(capabilities);
    

    Based on the suggestions by others, I did my changes as

    FirefoxProfile firefoxProfile = new FirefoxProfile();     
    firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk",
        "application/octet-stream");
    driver = new FirefoxDrvier(firefoxProfile);
    

    This served the purpose but unfortunately my other automation tests started failing. And the reason was, I have removed the capabilities which were being passed earlier.

    Some more browsing on net and found an alternate way. We can set the profile itself in the desired Capabilities.

    So the new working code looks like

    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    
    // add more capabilities as per your need.
    FirefoxProfile firefoxProfile = new FirefoxProfile();        
    firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk",
        "application/octet-stream");
    
    // set the firefoxprofile as a capability
    capabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
    driver = new FirefoxDriver(capabilities);
    

提交回复
热议问题